Commit ad4da535 authored by unknown's avatar unknown

Merge adventure.(none):/home/thek/Development/cpp/bug26277/my51-bug26277

into  adventure.(none):/home/thek/Development/cpp/mysql-5.1-runtime


mysql-test/t/sp-vars.test:
  Auto merged
sql/item_func.cc:
  Auto merged
sql/item_func.h:
  Auto merged
mysql-test/r/sp-vars.result:
  manual merge
parents bf1198a9 755ae21b
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -1202,3 +1202,29 @@ after substr str_remainder
after substr b,c
DROP PROCEDURE bug27415_text_test|
DROP PROCEDURE bug27415_text_test2|
drop function if exists f1;
drop table if exists t1;
create function f1() returns int
begin
if @a=1 then set @b='abc';
else set @b=1;
end if;
set @a=1;
return 0;
end|
create table t1 (a int)|
insert into t1 (a) values (1), (2)|
set @b=1|
set @a=0|
select f1(), @b from t1|
f1() @b
0 1
0 0
set @b:='test'|
set @a=0|
select f1(), @b from t1|
f1() @b
0 1
0 abc
drop function f1;
drop table t1;
......@@ -110,15 +110,24 @@ select 1 from t1 where cast('2000-01-01 12:01:01' as datetime) between start_dat
1
1
drop table t1;
select @d:=1111, year(@d), month(@d), day(@d), cast(@d as date);
@d:=1111 year(@d) month(@d) day(@d) cast(@d as date)
1111 2000 11 11 2000-11-11
select @d:=011111, year(@d), month(@d), day(@d), cast(@d as date);
@d:=011111 year(@d) month(@d) day(@d) cast(@d as date)
11111 2001 11 11 2001-11-11
select @d:=1311, year(@d), month(@d), day(@d), cast(@d as date);
@d:=1311 year(@d) month(@d) day(@d) cast(@d as date)
1311 NULL NULL NULL NULL
select @d:=1111;
@d:=1111
1111
select year(@d), month(@d), day(@d), cast(@d as date);
year(@d) month(@d) day(@d) cast(@d as date)
2000 11 11 2000-11-11
select @d:=011111;
@d:=011111
11111
select year(@d), month(@d), day(@d), cast(@d as date);
year(@d) month(@d) day(@d) cast(@d as date)
2001 11 11 2001-11-11
select @d:=1311;
@d:=1311
1311
select year(@d), month(@d), day(@d), cast(@d as date);
year(@d) month(@d) day(@d) cast(@d as date)
NULL NULL NULL NULL
Warnings:
Warning 1292 Incorrect datetime value: '1311'
Warning 1292 Incorrect datetime value: '1311'
......
......@@ -91,7 +91,7 @@ NULL test test
set @g=1;
select @g,(@g:=c),@g from t1;
@g (@g:=c) @g
1 test test
1 test 0
select @c, @d, @e, @f;
@c @d @e @f
1 1 2 test
......
......@@ -1412,3 +1412,39 @@ DROP PROCEDURE bug27415_text_test2|
DELIMITER ;|
# End of 5.0 tests.
#
# Bug #26277 User variable returns one type in SELECT @v and other for CREATE as SELECT @v
#
--disable_warnings
drop function if exists f1;
drop table if exists t1;
--enable_warnings
delimiter |;
create function f1() returns int
begin
if @a=1 then set @b='abc';
else set @b=1;
end if;
set @a=1;
return 0;
end|
create table t1 (a int)|
insert into t1 (a) values (1), (2)|
set @b=1|
set @a=0|
select f1(), @b from t1|
set @b:='test'|
set @a=0|
select f1(), @b from t1|
delimiter ;|
drop function f1;
drop table t1;
# End of 5.1 tests.
......@@ -128,9 +128,12 @@ drop table t1;
# Bug #23093: Implicit conversion of 9912101 to date does not match
# cast(9912101 as date)
#
select @d:=1111, year(@d), month(@d), day(@d), cast(@d as date);
select @d:=011111, year(@d), month(@d), day(@d), cast(@d as date);
select @d:=1311, year(@d), month(@d), day(@d), cast(@d as date);
select @d:=1111;
select year(@d), month(@d), day(@d), cast(@d as date);
select @d:=011111;
select year(@d), month(@d), day(@d), cast(@d as date);
select @d:=1311;
select year(@d), month(@d), day(@d), cast(@d as date);
create table t1 (d date , dt datetime , ts timestamp);
insert into t1 values (9912101,9912101,9912101);
insert into t1 values (11111,11111,11111);
......
......@@ -36,7 +36,6 @@
#define sp_restore_security_context(A,B) while (0) {}
#endif
bool check_reserved_words(LEX_STRING *name)
{
if (!my_strcasecmp(system_charset_info, name->str, "GLOBAL") ||
......@@ -4451,7 +4450,7 @@ int get_var_with_binlog(THD *thd, enum_sql_command sql_command,
> set @a:=1;
> insert into t1 values (@a), (@a:=@a+1), (@a:=@a+1);
We have to write to binlog value @a= 1.
We allocate the user_var_event on user_var_events_alloc pool, not on
the this-statement-execution pool because in SPs user_var_event objects
may need to be valid after current [SP] statement execution pool is
......@@ -4461,7 +4460,7 @@ int get_var_with_binlog(THD *thd, enum_sql_command sql_command,
if (!(user_var_event= (BINLOG_USER_VAR_EVENT *)
alloc_root(thd->user_var_events_alloc, size)))
goto err;
user_var_event->value= (char*) user_var_event +
ALIGN_SIZE(sizeof(BINLOG_USER_VAR_EVENT));
user_var_event->user_var_event= var_entry;
......@@ -4483,7 +4482,7 @@ int get_var_with_binlog(THD *thd, enum_sql_command sql_command,
var_entry->used_query_id= thd->query_id;
if (insert_dynamic(&thd->user_var_events, (gptr) &user_var_event))
goto err;
*out_entry= var_entry;
return 0;
......@@ -4492,7 +4491,6 @@ int get_var_with_binlog(THD *thd, enum_sql_command sql_command,
return 1;
}
void Item_func_get_user_var::fix_length_and_dec()
{
THD *thd=current_thd;
......@@ -4503,10 +4501,19 @@ void Item_func_get_user_var::fix_length_and_dec()
error= get_var_with_binlog(thd, thd->lex->sql_command, name, &var_entry);
/*
If the variable didn't exist it has been created as a STRING-type.
'var_entry' is NULL only if there occured an error during the call to
get_var_with_binlog.
*/
if (var_entry)
{
m_cached_result_type= var_entry->type;
unsigned_flag= var_entry->unsigned_flag;
max_length= var_entry->length;
collation.set(var_entry->collation);
switch (var_entry->type) {
switch(m_cached_result_type) {
case REAL_RESULT:
max_length= DBL_DIG + 8;
break;
......@@ -4531,6 +4538,8 @@ void Item_func_get_user_var::fix_length_and_dec()
{
collation.set(&my_charset_bin, DERIVATION_IMPLICIT);
null_value= 1;
m_cached_result_type= STRING_RESULT;
max_length= MAX_BLOB_WIDTH;
}
if (error)
......@@ -4548,12 +4557,7 @@ bool Item_func_get_user_var::const_item() const
enum Item_result Item_func_get_user_var::result_type() const
{
user_var_entry *entry;
if (!(entry = (user_var_entry*) hash_search(&current_thd->user_vars,
(byte*) name.str,
name.length)))
return STRING_RESULT;
return entry->type;
return m_cached_result_type;
}
......
......@@ -1256,11 +1256,12 @@ class Item_func_get_user_var :public Item_func,
private Settable_routine_parameter
{
user_var_entry *var_entry;
Item_result m_cached_result_type;
public:
LEX_STRING name; // keep it public
Item_func_get_user_var(LEX_STRING a):
Item_func(), name(a) {}
Item_func(), name(a), m_cached_result_type(STRING_RESULT) {}
enum Functype functype() const { return GUSERVAR_FUNC; }
LEX_STRING get_name() { return name; }
double val_real();
......@@ -1274,13 +1275,11 @@ class Item_func_get_user_var :public Item_func,
We must always return variables as strings to guard against selects of type
select @t1:=1,@t1,@t:="hello",@t from foo where (@t1:= t2.b)
*/
enum_field_types field_type() const { return MYSQL_TYPE_VARCHAR; }
const char *func_name() const { return "get_user_var"; }
bool const_item() const;
table_map used_tables() const
{ return const_item() ? 0 : RAND_TABLE_BIT; }
bool eq(const Item *item, bool binary_cmp) const;
private:
bool set_value(THD *thd, sp_rcontext *ctx, Item **it);
......
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