From d099c0ed40e0f5575407a904797821e09f38a24d Mon Sep 17 00:00:00 2001 From: "guilhem@gbichot2" <> Date: Thu, 2 Oct 2003 16:19:33 +0200 Subject: [PATCH] Had mangled the order of if()s in a previous changeset (1.1596) (not pushed), correcting it now. Thanks Dmitri for spotting this. --- mysql-test/r/user_var.result | 4 ++++ mysql-test/t/user_var.test | 3 +++ sql/item_func.cc | 22 ++++++++++------------ 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/mysql-test/r/user_var.result b/mysql-test/r/user_var.result index 23253f60de9..b7c64551dc0 100644 --- a/mysql-test/r/user_var.result +++ b/mysql-test/r/user_var.result @@ -5,6 +5,10 @@ set @a := connection_id() + 3; select @a - connection_id(); @a - connection_id() 3 +set @b := 1; +select @b; +@b +1 CREATE TABLE t1 ( i int not null, v int not null,index (i)); insert into t1 values (1,1),(1,3),(2,1); create table t2 (i int not null, unique (i)); diff --git a/mysql-test/t/user_var.test b/mysql-test/t/user_var.test index 514eace25a3..947c944c79e 100644 --- a/mysql-test/t/user_var.test +++ b/mysql-test/t/user_var.test @@ -8,6 +8,9 @@ set @a := foo; set @a := connection_id() + 3; select @a - connection_id(); +set @b := 1; +select @b; + # Check using and setting variables with SELECT DISTINCT CREATE TABLE t1 ( i int not null, v int not null,index (i)); diff --git a/sql/item_func.cc b/sql/item_func.cc index 8073ee60572..0f9ee512be1 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -2343,25 +2343,23 @@ longlong Item_func_get_user_var::val_int() void Item_func_get_user_var::fix_length_and_dec() { THD *thd=current_thd; - - if (!(opt_bin_log && is_update_query(thd->lex.sql_command))) - return; - BINLOG_USER_VAR_EVENT *user_var_event; maybe_null=1; decimals=NOT_FIXED_DEC; max_length=MAX_BLOB_WIDTH; - /* - If the variable does not exist, it's NULL, but we want to create it so - that it gets into the binlog (if it didn't, the slave could be - influenced by a variable of the same name previously set by another - thread). - */ - - if (!(var_entry= get_variable(&thd->user_vars, name, 0))) + var_entry= get_variable(&thd->user_vars, name, 0); + + if (!(opt_bin_log && is_update_query(thd->lex.sql_command))) + return; + + if (!var_entry) { /* + If the variable does not exist, it's NULL, but we want to create it so + that it gets into the binlog (if it didn't, the slave could be + influenced by a variable of the same name previously set by another + thread). We create it like if it had been explicitely set with SET before. The 'new' mimicks what sql_yacc.yy does when 'SET @a=10;'. sql_set_variables() is what is called from 'case SQLCOM_SET_OPTION'