Commit 2d9e4e66 authored by unknown's avatar unknown

fixed bug #1194

(changes in Item_func_set_user_var::update, ::val, ::val_str, ::val_int)


mysql-test/r/user_var.result:
  added tests for bug #1194
mysql-test/t/user_var.test:
  added tests for bug #1194
parent f46ca5fb
......@@ -42,3 +42,35 @@ select @a:=10, @b:=2, @a > @b, @a < @b;
select @a:="10", @b:="2", @a > @b, @a < @b;
@a:="10" @b:="2" @a > @b @a < @b
10 2 0 1
select @a:=1;
@a:=1
1
select @a, @a:=1;
@a @a:=1
1 1
create table t1 (id int);
insert into t1 values (1);
select @c:=0;
@c:=0
0
update t1 SET id=(@c:=@c+1);
select @c;
@c
1
select @c:=0;
@c:=0
0
update t1 set id=(@c:=@c+1);
select @c;
@c
1
select @c:=0;
@c:=0
0
select @c:=@c+1;
@c:=@c+1
1
drop table t1;
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;
@a:=10 @b:=2 @a>@b @a:="10" @b:="2" @a>@b @a:=10 @b:=2 @a>@b @a:="10" @b:="2" @a>@b
10 2 1 10 2 0 10 2 1 10 2 0
......@@ -23,3 +23,22 @@ select @a:=10, @b:=1, @a > @b, @a < @b;
select @a:="10", @b:="1", @a > @b, @a < @b;
select @a:=10, @b:=2, @a > @b, @a < @b;
select @a:="10", @b:="2", @a > @b, @a < @b;
# Fixed bug #1194
select @a:=1;
select @a, @a:=1;
create table t1 (id int);
insert into t1 values (1);
select @c:=0;
update t1 SET id=(@c:=@c+1);
select @c;
select @c:=0;
update t1 set id=(@c:=@c+1);
select @c;
select @c:=0;
select @c:=@c+1;
drop table t1;
# just fof fun :)
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;
\ No newline at end of file
......@@ -1903,48 +1903,132 @@ void Item_func_set_user_var::update_hash(void *ptr, uint length,
bool
Item_func_set_user_var::update()
{
DBUG_ENTER("Item_func_set_user_var::update");
switch (cached_result_type) {
case REAL_RESULT:
(void) val();
{
double value=args[0]->val();
update_hash((void*) &value,sizeof(value), REAL_RESULT);
break;
}
case INT_RESULT:
(void) val_int();
{
longlong value=args[0]->val_int();
update_hash((void*) &value,sizeof(longlong),INT_RESULT);
break;
}
case STRING_RESULT:
{
char buffer[MAX_FIELD_WIDTH];
String tmp(buffer,sizeof(buffer));
(void) val_str(&tmp);
String *res=args[0]->val_str(&tmp);
if (!res) // Null value
update_hash((void*) 0,0,STRING_RESULT);
else
update_hash(res->c_ptr(),res->length()+1,STRING_RESULT);
break;
}
return current_thd->fatal_error;
}
DBUG_RETURN(current_thd->fatal_error);
}
double
Item_func_set_user_var::val()
{
DBUG_ENTER("Item_func_set_user_var::val");
switch (cached_result_type) {
case REAL_RESULT:
{
double value=args[0]->val();
update_hash((void*) &value,sizeof(value), REAL_RESULT);
return value;
}
case INT_RESULT:
{
longlong value=args[0]->val_int();
update_hash((void*) &value,sizeof(longlong),INT_RESULT);
return value;
}
case STRING_RESULT:
{
char buffer[MAX_FIELD_WIDTH];
String tmp(buffer,sizeof(buffer));
String *res=args[0]->val_str(&tmp);
if (!res) // Null value
update_hash((void*) 0,0,STRING_RESULT);
else
update_hash(res->c_ptr(),res->length()+1,STRING_RESULT);
return atof(res->c_ptr());
}
}
DBUG_RETURN(args[0]->val());
}
longlong
Item_func_set_user_var::val_int()
{
DBUG_ENTER("Item_func_set_user_var::val_int");
switch (cached_result_type) {
case REAL_RESULT:
{
double value=args[0]->val();
update_hash((void*) &value,sizeof(value), REAL_RESULT);
return (longlong)value;
}
case INT_RESULT:
{
longlong value=args[0]->val_int();
update_hash((void*) &value,sizeof(longlong),INT_RESULT);
return value;
}
case STRING_RESULT:
{
char buffer[MAX_FIELD_WIDTH];
String tmp(buffer,sizeof(buffer));
String *res=args[0]->val_str(&tmp);
if (!res) // Null value
update_hash((void*) 0,0,STRING_RESULT);
else
update_hash(res->c_ptr(),res->length()+1,STRING_RESULT);
return strtoull(res->c_ptr(),NULL,10);
}
}
DBUG_RETURN(args[0]->val_int());
}
String *
Item_func_set_user_var::val_str(String *str)
{
String *res=args[0]->val_str(str);
DBUG_ENTER("Item_func_set_user_var::val_str");
switch (cached_result_type) {
case REAL_RESULT:
{
double value=args[0]->val();
update_hash((void*) &value,sizeof(value), REAL_RESULT);
str->set(value,decimals);
return str;
}
case INT_RESULT:
{
longlong value=args[0]->val_int();
update_hash((void*) &value,sizeof(longlong),INT_RESULT);
str->set(value,decimals);
return str;
}
case STRING_RESULT:
{
char buffer[MAX_FIELD_WIDTH];
String tmp(buffer,sizeof(buffer));
String *res=args[0]->val_str(&tmp);
if (!res) // Null value
update_hash((void*) 0,0,STRING_RESULT);
else
update_hash(res->c_ptr(),res->length()+1,STRING_RESULT);
return res;
}
}
DBUG_RETURN(args[0]->val_str(str));
}
......@@ -1973,6 +2057,7 @@ user_var_entry *Item_func_get_user_var::get_entry()
String *
Item_func_get_user_var::val_str(String *str)
{
DBUG_ENTER("Item_func_get_user_var::val_str");
user_var_entry *entry=get_entry();
if (!entry)
return NULL;
......@@ -1991,7 +2076,7 @@ Item_func_get_user_var::val_str(String *str)
}
break;
}
return str;
DBUG_RETURN(str);
}
......
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