summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <holyfoot/hf@hfmain.(none)>2007-07-27 22:43:33 +0500
committerunknown <holyfoot/hf@hfmain.(none)>2007-07-27 22:43:33 +0500
commit8feaed2ae75ea20a6f6e94aac7dd404fd2953835 (patch)
tree5b32826bab6d3dc94b70e85c621bbf3ff46e5035
parent54c9742922864ee711e024bb93307c553d66fb38 (diff)
parentd27bf14ed7aab39b8b83d0eed34cb3ba4417de35 (diff)
downloadmariadb-git-8feaed2ae75ea20a6f6e94aac7dd404fd2953835.tar.gz
Merge mysql.com:/home/hf/work/29878/my50-29878
into mysql.com:/home/hf/work/29878/my51-29878 mysql-test/suite/rpl/r/rpl_session_var.result: Auto merged mysql-test/suite/rpl/t/rpl_session_var.test: Auto merged sql/item.cc: Auto merged sql/item.h: Auto merged sql/item_strfunc.h: Auto merged
-rw-r--r--mysql-test/suite/rpl/r/rpl_session_var.result10
-rw-r--r--mysql-test/suite/rpl/t/rpl_session_var.test22
-rw-r--r--sql/item.cc52
-rw-r--r--sql/item.h6
-rw-r--r--sql/item_strfunc.h4
5 files changed, 79 insertions, 15 deletions
diff --git a/mysql-test/suite/rpl/r/rpl_session_var.result b/mysql-test/suite/rpl/r/rpl_session_var.result
index b5b4b815ade..787899932d6 100644
--- a/mysql-test/suite/rpl/r/rpl_session_var.result
+++ b/mysql-test/suite/rpl/r/rpl_session_var.result
@@ -41,3 +41,13 @@ select * from t2 order by b;
b a
1 1
drop table t1,t2;
+CREATE TABLE t1 (
+`id` int(11) NOT NULL auto_increment,
+`data` varchar(100),
+PRIMARY KEY (`id`)
+) ENGINE=MyISAM;
+INSERT INTO t1(data) VALUES(SESSION_USER());
+SELECT * FROM t1;
+id data
+1
+drop table t1;
diff --git a/mysql-test/suite/rpl/t/rpl_session_var.test b/mysql-test/suite/rpl/t/rpl_session_var.test
index a6f4b496a23..8231a0dbefd 100644
--- a/mysql-test/suite/rpl/t/rpl_session_var.test
+++ b/mysql-test/suite/rpl/t/rpl_session_var.test
@@ -40,3 +40,25 @@ drop table t1,t2;
save_master_pos;
connection slave;
sync_with_master;
+
+#
+# Bug #29878 Garbage data generation when executing SESSION_USER() on a slave.
+#
+
+connection master;
+CREATE TABLE t1 (
+ `id` int(11) NOT NULL auto_increment,
+ `data` varchar(100),
+ PRIMARY KEY (`id`)
+ ) ENGINE=MyISAM;
+
+INSERT INTO t1(data) VALUES(SESSION_USER());
+save_master_pos;
+connection slave;
+sync_with_master;
+SELECT * FROM t1;
+connection master;
+drop table t1;
+save_master_pos;
+connection slave;
+sync_with_master;
diff --git a/sql/item.cc b/sql/item.cc
index 711a21ecbec..d6785461a7d 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -334,6 +334,37 @@ int Item::save_date_in_field(Field *field)
}
+/*
+ Store the string value in field directly
+
+ SYNOPSIS
+ Item::save_str_value_in_field()
+ field a pointer to field where to store
+ result the pointer to the string value to be stored
+
+ DESCRIPTION
+ The method is used by Item_*::save_in_field implementations
+ when we don't need to calculate the value to store
+ See Item_string::save_in_field() implementation for example
+
+ IMPLEMENTATION
+ Check if the Item is null and stores the NULL or the
+ result value in the field accordingly.
+
+ RETURN
+ Nonzero value if error
+*/
+
+int Item::save_str_value_in_field(Field *field, String *result)
+{
+ if (null_value)
+ return set_field_to_null(field);
+ field->set_notnull();
+ return field->store(result->ptr(), result->length(),
+ collation.collation);
+}
+
+
Item::Item():
rsize(0), name(0), orig_name(0), name_length(0), fixed(0),
is_autogenerated_name(TRUE),
@@ -3046,16 +3077,6 @@ my_decimal *Item_copy_string::val_decimal(my_decimal *decimal_value)
}
-
-int Item_copy_string::save_in_field(Field *field, bool no_conversions)
-{
- if (null_value)
- return set_field_to_null(field);
- field->set_notnull();
- return field->store(str_value.ptr(),str_value.length(),
- collation.collation);
-}
-
/*
Functions to convert item to field (for send_fields)
*/
@@ -4508,6 +4529,12 @@ int Item_null::save_safe_in_field(Field *field)
}
+/*
+ This implementation can lose str_value content, so if the
+ Item uses str_value to store something, it should
+ reimplement it's ::save_in_field() as Item_string, for example, does
+*/
+
int Item::save_in_field(Field *field, bool no_conversions)
{
int error;
@@ -4565,10 +4592,7 @@ int Item_string::save_in_field(Field *field, bool no_conversions)
{
String *result;
result=val_str(&str_value);
- if (null_value)
- return set_field_to_null(field);
- field->set_notnull();
- return field->store(result->ptr(),result->length(),collation.collation);
+ return save_str_value_in_field(field, result);
}
diff --git a/sql/item.h b/sql/item.h
index 432da6c3a1c..5f4e0117d02 100644
--- a/sql/item.h
+++ b/sql/item.h
@@ -653,6 +653,7 @@ public:
int save_time_in_field(Field *field);
int save_date_in_field(Field *field);
+ int save_str_value_in_field(Field *field, String *result);
virtual Field *get_tmp_table_field() { return 0; }
/* This is also used to create fields in CREATE ... SELECT: */
@@ -2293,7 +2294,10 @@ public:
my_decimal *val_decimal(my_decimal *);
void make_field(Send_field *field) { item->make_field(field); }
void copy();
- int save_in_field(Field *field, bool no_conversions);
+ int save_in_field(Field *field, bool no_conversions)
+ {
+ return save_str_value_in_field(field, &str_value);
+ }
table_map used_tables() const { return (table_map) 1L; }
bool const_item() const { return 0; }
bool is_null() { return null_value; }
diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h
index 6d2d9c199c9..ea9517976a8 100644
--- a/sql/item_strfunc.h
+++ b/sql/item_strfunc.h
@@ -427,6 +427,10 @@ public:
}
const char *func_name() const { return "user"; }
const char *fully_qualified_func_name() const { return "user()"; }
+ int save_in_field(Field *field, bool no_conversions)
+ {
+ return save_str_value_in_field(field, &str_value);
+ }
};