Below is the list of changes that have just been committed into a local
5.1 repository of thek. When thek does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html
ChangeSet@stripped, 2007-05-18 14:29:24+02:00, thek@adventure.(none) +4 -0
Merge adventure.(none):/home/thek/Development/cpp/bug26277/my51-bug26277
into adventure.(none):/home/thek/Development/cpp/mysql-5.1-runtime
MERGE: 1.2502.7.1
mysql-test/r/sp-vars.result@stripped, 2007-05-18 14:29:22+02:00, thek@adventure.(none) +26 -26
manual merge
MERGE: 1.10.1.1
mysql-test/t/sp-vars.test@stripped, 2007-05-18 14:28:00+02:00, thek@adventure.(none) +0 -0
Auto merged
MERGE: 1.6.1.1
sql/item_func.cc@stripped, 2007-05-18 14:28:00+02:00, thek@adventure.(none) +0 -0
Auto merged
MERGE: 1.380.7.1
sql/item_func.h@stripped, 2007-05-18 14:28:00+02:00, thek@adventure.(none) +0 -0
Auto merged
MERGE: 1.169.1.1
# This is a BitKeeper patch. What follows are the unified diffs for the
# set of deltas contained in the patch. The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User: thek
# Host: adventure.(none)
# Root: /home/thek/Development/cpp/mysql-5.1-runtime/RESYNC
--- 1.392/sql/item_func.cc 2007-05-15 16:03:50 +02:00
+++ 1.393/sql/item_func.cc 2007-05-18 14:28:00 +02:00
@@ -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_s
> 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_s
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_s
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 @@ err:
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_
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_
{
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(
enum Item_result Item_func_get_user_var::result_type() const
{
- user_var_entry *entry;
- if (!(entry = (user_var_entry*) hash_search(¤t_thd->user_vars,
- (byte*) name.str,
- name.length)))
- return STRING_RESULT;
- return entry->type;
+ return m_cached_result_type;
}
--- 1.173/sql/item_func.h 2007-05-11 15:16:06 +02:00
+++ 1.174/sql/item_func.h 2007-05-18 14:28:00 +02:00
@@ -1256,11 +1256,12 @@ class Item_func_get_user_var :public Ite
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 @@ public:
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);
--- 1.13/mysql-test/r/sp-vars.result 2007-05-16 14:48:28 +02:00
+++ 1.14/mysql-test/r/sp-vars.result 2007-05-18 14:29:22 +02:00
@@ -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;
--- 1.7/mysql-test/t/sp-vars.test 2007-05-16 14:48:28 +02:00
+++ 1.8/mysql-test/t/sp-vars.test 2007-05-18 14:28:00 +02:00
@@ -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.
+
| Thread |
|---|
| • bk commit into 5.1 tree (thek:1.2528) | kpettersson | 18 May |