summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorunknown <monty@donna.mysql.fi>2001-03-15 11:55:44 +0200
committerunknown <monty@donna.mysql.fi>2001-03-15 11:55:44 +0200
commitc669254da76877d1ca9fc78c1065604a797935ef (patch)
tree4cbc0ef76ce9d184843d9c7b9ab153d5f4d8e35b /sql
parent41ed01413fdfcfa8bec77c8ebd1a6850feb04463 (diff)
downloadmariadb-git-c669254da76877d1ca9fc78c1065604a797935ef.tar.gz
Added tests if a user variable is changed in the same query.
Docs/manual.texi: Updated info about some common problems. mysql-test/r/user_var.result: Added tests of using user variables. mysql-test/t/user_var.test: Added tests of using user variables.
Diffstat (limited to 'sql')
-rw-r--r--sql/item_func.cc6
-rw-r--r--sql/item_func.h9
-rw-r--r--sql/sql_class.h2
3 files changed, 12 insertions, 5 deletions
diff --git a/sql/item_func.cc b/sql/item_func.cc
index ef46a624aaf..61e64be1e74 100644
--- a/sql/item_func.cc
+++ b/sql/item_func.cc
@@ -1606,6 +1606,7 @@ static user_var_entry *get_variable(HASH *hash, LEX_STRING &name,
entry->name.length=name.length;
entry->value=0;
entry->length=0;
+ entry->update_query_id=0;
entry->type=STRING_RESULT;
memcpy(entry->name.str, name.str, name.length+1);
if (hash_insert(hash,(byte*) entry))
@@ -1625,6 +1626,7 @@ bool Item_func_set_user_var::fix_fields(THD *thd,TABLE_LIST *tables)
if (Item_func::fix_fields(thd,tables) ||
!(entry= get_variable(&thd->user_vars, name, 1)))
return 1;
+ entry->update_query_id=thd->query_id;
return 0;
}
@@ -1809,10 +1811,12 @@ longlong Item_func_get_user_var::val_int()
void Item_func_get_user_var::fix_length_and_dec()
{
+ THD *thd=current_thd;
maybe_null=1;
decimals=NOT_FIXED_DEC;
max_length=MAX_BLOB_WIDTH;
- entry= get_variable(&current_thd->user_vars, name, 0);
+ if ((entry= get_variable(&thd->user_vars, name, 0)))
+ const_var_flag= thd->query_id != entry->update_query_id;
}
diff --git a/sql/item_func.h b/sql/item_func.h
index 595329d4bf4..ac4c230f312 100644
--- a/sql/item_func.h
+++ b/sql/item_func.h
@@ -825,9 +825,11 @@ class Item_func_get_user_var :public Item_func
{
LEX_STRING name;
user_var_entry *entry;
+ bool const_var_flag;
public:
- Item_func_get_user_var(LEX_STRING a): Item_func(), name(a) {}
+ Item_func_get_user_var(LEX_STRING a):
+ Item_func(), name(a), const_var_flag(1) {}
user_var_entry *get_entry();
double val();
longlong val_int();
@@ -835,8 +837,9 @@ public:
void fix_length_and_dec();
enum Item_result result_type() const;
const char *func_name() const { return "get_user_var"; }
- bool const_item() const { return 0; }
- table_map used_tables() const { return RAND_TABLE_BIT; }
+ bool const_item() const { return const_var_flag; }
+ table_map used_tables() const
+ { return const_var_flag ? 0 : RAND_TABLE_BIT; }
};
class Item_func_inet_aton : public Item_int_func
diff --git a/sql/sql_class.h b/sql/sql_class.h
index 37ef237757d..1b444598401 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -550,7 +550,7 @@ class user_var_entry
public:
LEX_STRING name;
char *value;
- ulong length;
+ ulong length, update_query_id;
Item_result type;
};