diff options
author | unknown <thek@adventure.(none)> | 2007-05-18 14:29:24 +0200 |
---|---|---|
committer | unknown <thek@adventure.(none)> | 2007-05-18 14:29:24 +0200 |
commit | ad4da53510fe17b7b20912753232719fd8d3e033 (patch) | |
tree | 4f8326572903715f38fff117eb849e5a7360745c /sql | |
parent | bf1198a91354a659a812a7490ac180768b19fe05 (diff) | |
parent | 755ae21b826d6e644560b0ad397eb46cd7191369 (diff) | |
download | mariadb-git-ad4da53510fe17b7b20912753232719fd8d3e033.tar.gz |
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
Diffstat (limited to 'sql')
-rw-r--r-- | sql/item_func.cc | 28 | ||||
-rw-r--r-- | sql/item_func.h | 5 |
2 files changed, 18 insertions, 15 deletions
diff --git a/sql/item_func.cc b/sql/item_func.cc index d30bc6acf2a..cea51c85a89 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -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 @@ 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_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(¤t_thd->user_vars, - (byte*) name.str, - name.length))) - return STRING_RESULT; - return entry->type; + return m_cached_result_type; } diff --git a/sql/item_func.h b/sql/item_func.h index b76877f90bc..827bfd56e87 100644 --- a/sql/item_func.h +++ b/sql/item_func.h @@ -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 @@ 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); |