Skip to content

Commit 14a2466

Browse files
author
vva@eagle.mysql.r18.ru
committed
Merge eagle.mysql.r18.ru:/home/vva/work/mysql.orig/clear/mysql-4.0
into eagle.mysql.r18.ru:/home/vva/work/BUG_1194/mysql-4.0
2 parents 7aae6ba + 761c790 commit 14a2466

File tree

4 files changed

+119
-26
lines changed

4 files changed

+119
-26
lines changed

mysql-test/r/user_var.result

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,35 @@ select @a:=10, @b:=2, @a > @b, @a < @b;
4242
select @a:="10", @b:="2", @a > @b, @a < @b;
4343
@a:="10" @b:="2" @a > @b @a < @b
4444
10 2 0 1
45+
select @a:=1;
46+
@a:=1
47+
1
48+
select @a, @a:=1;
49+
@a @a:=1
50+
1 1
51+
create table t1 (id int);
52+
insert into t1 values (1);
53+
select @c:=0;
54+
@c:=0
55+
0
56+
update t1 SET id=(@c:=@c+1);
57+
select @c;
58+
@c
59+
1
60+
select @c:=0;
61+
@c:=0
62+
0
63+
update t1 set id=(@c:=@c+1);
64+
select @c;
65+
@c
66+
1
67+
select @c:=0;
68+
@c:=0
69+
0
70+
select @c:=@c+1;
71+
@c:=@c+1
72+
1
73+
drop table t1;
74+
select @a:=10, @b:=2, @a>@b, @a:="10", @b:="2", @a>@b, @a:=10, @b:=2, @a>@b, @a:="10", @b:="2", @a>@b;
75+
@a:=10 @b:=2 @a>@b @a:="10" @b:="2" @a>@b @a:=10 @b:=2 @a>@b @a:="10" @b:="2" @a>@b
76+
10 2 1 10 2 0 10 2 1 10 2 0

mysql-test/t/user_var.test

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,22 @@ select @a:=10, @b:=1, @a > @b, @a < @b;
2323
select @a:="10", @b:="1", @a > @b, @a < @b;
2424
select @a:=10, @b:=2, @a > @b, @a < @b;
2525
select @a:="10", @b:="2", @a > @b, @a < @b;
26+
27+
# Fixed bug #1194
28+
select @a:=1;
29+
select @a, @a:=1;
30+
31+
create table t1 (id int);
32+
insert into t1 values (1);
33+
select @c:=0;
34+
update t1 SET id=(@c:=@c+1);
35+
select @c;
36+
select @c:=0;
37+
update t1 set id=(@c:=@c+1);
38+
select @c;
39+
select @c:=0;
40+
select @c:=@c+1;
41+
drop table t1;
42+
43+
# just fof fun :)
44+
select @a:=10, @b:=2, @a>@b, @a:="10", @b:="2", @a>@b, @a:=10, @b:=2, @a>@b, @a:="10", @b:="2", @a>@b;

sql/item_func.cc

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1899,52 +1899,61 @@ void Item_func_set_user_var::update_hash(void *ptr, uint length,
18991899
return;
19001900
}
19011901

1902-
19031902
bool
19041903
Item_func_set_user_var::update()
19051904
{
1905+
DBUG_ENTER("Item_func_set_user_var::update");
19061906
switch (cached_result_type) {
1907-
case REAL_RESULT:
1908-
(void) val();
1909-
break;
1910-
case INT_RESULT:
1911-
(void) val_int();
1912-
break;
1913-
case STRING_RESULT:
1914-
char buffer[MAX_FIELD_WIDTH];
1915-
String tmp(buffer,sizeof(buffer));
1916-
(void) val_str(&tmp);
1917-
break;
1907+
case REAL_RESULT: (void)native_val(); break;
1908+
case INT_RESULT: (void)native_val_int(); break;
1909+
case STRING_RESULT: (void)native_val_str(); break;
19181910
}
1919-
return current_thd->fatal_error;
1911+
DBUG_RETURN(current_thd->fatal_error);
19201912
}
19211913

19221914

19231915
double
19241916
Item_func_set_user_var::val()
19251917
{
1926-
double value=args[0]->val();
1927-
update_hash((void*) &value,sizeof(value), REAL_RESULT);
1928-
return value;
1918+
DBUG_ENTER("Item_func_set_user_var::val");
1919+
switch (cached_result_type) {
1920+
case REAL_RESULT: return native_val(); break;
1921+
case INT_RESULT: return native_val_int(); break;
1922+
case STRING_RESULT:
1923+
{
1924+
String *res= native_val_str();
1925+
return !res ? 0 : atof(res->c_ptr());
1926+
}
1927+
}
1928+
DBUG_RETURN(args[0]->val());
19291929
}
19301930

19311931
longlong
19321932
Item_func_set_user_var::val_int()
19331933
{
1934-
longlong value=args[0]->val_int();
1935-
update_hash((void*) &value,sizeof(longlong),INT_RESULT);
1936-
return value;
1934+
DBUG_ENTER("Item_func_set_user_var::val_int");
1935+
switch (cached_result_type) {
1936+
case REAL_RESULT: return (longlong)native_val(); break;
1937+
case INT_RESULT: return native_val_int(); break;
1938+
case STRING_RESULT:
1939+
{
1940+
String *res= native_val_str();
1941+
return !res ? 0 : strtoull(res->c_ptr(),NULL,10);
1942+
}
1943+
}
1944+
DBUG_RETURN(args[0]->val_int());
19371945
}
19381946

19391947
String *
19401948
Item_func_set_user_var::val_str(String *str)
19411949
{
1942-
String *res=args[0]->val_str(str);
1943-
if (!res) // Null value
1944-
update_hash((void*) 0,0,STRING_RESULT);
1945-
else
1946-
update_hash(res->c_ptr(),res->length()+1,STRING_RESULT);
1947-
return res;
1950+
DBUG_ENTER("Item_func_set_user_var::val_str");
1951+
switch (cached_result_type) {
1952+
case REAL_RESULT: str->set(native_val(),decimals); break;
1953+
case INT_RESULT: str->set(native_val_int(),decimals); break;
1954+
case STRING_RESULT: str= native_val_str(str); break;
1955+
}
1956+
DBUG_RETURN(str);
19481957
}
19491958

19501959

@@ -1973,6 +1982,7 @@ user_var_entry *Item_func_get_user_var::get_entry()
19731982
String *
19741983
Item_func_get_user_var::val_str(String *str)
19751984
{
1985+
DBUG_ENTER("Item_func_get_user_var::val_str");
19761986
user_var_entry *entry=get_entry();
19771987
if (!entry)
19781988
return NULL;
@@ -1991,7 +2001,7 @@ Item_func_get_user_var::val_str(String *str)
19912001
}
19922002
break;
19932003
}
1994-
return str;
2004+
DBUG_RETURN(str);
19952005
}
19962006

19972007

sql/item_func.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -889,6 +889,38 @@ class Item_func_set_user_var :public Item_func
889889
LEX_STRING name;
890890
user_var_entry *entry;
891891

892+
double native_val()
893+
{
894+
double value=args[0]->val();
895+
update_hash((void*) &value,sizeof(value), REAL_RESULT);
896+
return value;
897+
}
898+
899+
longlong native_val_int()
900+
{
901+
longlong value=args[0]->val_int();
902+
update_hash((void*) &value,sizeof(longlong),INT_RESULT);
903+
return value;
904+
}
905+
906+
String *native_val_str(String *str)
907+
{
908+
char buffer[MAX_FIELD_WIDTH];
909+
String *res=args[0]->val_str(str);
910+
if (!res) // Null value
911+
update_hash((void*) 0,0,STRING_RESULT);
912+
else
913+
update_hash(res->c_ptr(),res->length()+1,STRING_RESULT);
914+
return res;
915+
}
916+
917+
String *native_val_str()
918+
{
919+
char buffer[MAX_FIELD_WIDTH];
920+
String tmp(buffer,sizeof(buffer));
921+
return native_val_str(&tmp);
922+
}
923+
892924
public:
893925
Item_func_set_user_var(LEX_STRING a,Item *b): Item_func(b), name(a) {}
894926
double val();

0 commit comments

Comments
 (0)