summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbell@sanja.is.com.ua <>2002-10-11 17:00:11 +0300
committerbell@sanja.is.com.ua <>2002-10-11 17:00:11 +0300
commitb79a4c01e7c31a7dea21e1236fe9779175c7d018 (patch)
tree0c5bb849ce3914aa6d4b3753a1a3e6e486a05b3f
parentde434ff8ab41a8bd93a847ee54dc96308a1b1cfc (diff)
downloadmariadb-git-b79a4c01e7c31a7dea21e1236fe9779175c7d018.tar.gz
fixed bug in subselect value storing
-rw-r--r--mysql-test/r/subselect.result3
-rw-r--r--mysql-test/t/subselect.test1
-rw-r--r--sql/item_subselect.cc2
-rw-r--r--sql/item_subselect.h13
-rw-r--r--sql/sql_class.cc11
5 files changed, 24 insertions, 6 deletions
diff --git a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result
index 2618741a520..1ea59677c6e 100644
--- a/mysql-test/r/subselect.result
+++ b/mysql-test/r/subselect.result
@@ -159,6 +159,9 @@ UNIQUE KEY `email` (`email`)
INSERT INTO inscrit (pseudo,email) VALUES ('joce','test');
INSERT INTO inscrit (pseudo,email) VALUES ('joce1','test1');
INSERT INTO inscrit (pseudo,email) VALUES ('2joce1','2test1');
+SELECT pseudo FROM inscrit WHERE pseudo=(SELECT pseudo FROM inscrit WHERE pseudo='joce');
+pseudo
+joce
SELECT pseudo FROM inscrit WHERE pseudo=(SELECT pseudo FROM inscrit WHERE pseudo LIKE '%joce%');
Subselect returns more than 1 record
drop table if exists t1,t2,t3,t4,t5,attend,clinic,inscrit;
diff --git a/mysql-test/t/subselect.test b/mysql-test/t/subselect.test
index c34332d6d90..6b3401383c8 100644
--- a/mysql-test/t/subselect.test
+++ b/mysql-test/t/subselect.test
@@ -82,6 +82,7 @@ CREATE TABLE `inscrit` (
INSERT INTO inscrit (pseudo,email) VALUES ('joce','test');
INSERT INTO inscrit (pseudo,email) VALUES ('joce1','test1');
INSERT INTO inscrit (pseudo,email) VALUES ('2joce1','2test1');
+SELECT pseudo FROM inscrit WHERE pseudo=(SELECT pseudo FROM inscrit WHERE pseudo='joce');
-- error 1240
SELECT pseudo FROM inscrit WHERE pseudo=(SELECT pseudo FROM inscrit WHERE pseudo LIKE '%joce%');
diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc
index 2d08b9cb6b5..26cc376739a 100644
--- a/sql/item_subselect.cc
+++ b/sql/item_subselect.cc
@@ -150,6 +150,8 @@ String *Item_singleval_subselect::val_str (String *str)
assign_null();
return 0;
}
+ // Assign temporary buffer with stored value
+ str_value.set(string_value, 0, string_value.length());
return &str_value;
}
diff --git a/sql/item_subselect.h b/sql/item_subselect.h
index 5d070871b49..79b6b3a4292 100644
--- a/sql/item_subselect.h
+++ b/sql/item_subselect.h
@@ -80,10 +80,16 @@ public:
class Item_singleval_subselect :public Item_subselect
{
protected:
- longlong int_value; /* here stored integer value of this item */
- double real_value; /* here stored real value of this item */
+ longlong int_value; /* Here stored integer value of this item */
+ double real_value; /* Here stored real value of this item */
+ /*
+ Here stored string value of this item.
+ (str_value used only as temporary buffer, because it can be changed
+ by Item::save_field)
+ */
+ String string_value;
enum Item_result res_type; /* type of results */
-
+
public:
Item_singleval_subselect(THD *thd, st_select_lex *select_lex);
Item_singleval_subselect(Item_singleval_subselect *item):
@@ -91,6 +97,7 @@ public:
{
int_value= item->int_value;
real_value= item->real_value;
+ string_value.set(item->string_value, 0, item->string_value.length());
max_length= item->max_length;
decimals= item->decimals;
res_type= item->res_type;
diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index 648e05c1610..f778a721f54 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -884,9 +884,14 @@ bool select_singleval_subselect::send_data(List<Item> &items)
it->decimals= val_item->decimals;
it->binary= val_item->binary;
it->int_value= val_item->val_int();
- String *s= val_item->val_str(&it->str_value);
- if (s != &it->str_value)
- it->str_value.set(*s, 0, s->length());
+ String *s= val_item->val_str(&it->string_value);
+ if (s != &it->string_value)
+ {
+ it->string_value.set(*s, 0, s->length());
+ }
+ // TODO: remove when correct charset handling appeared for Item
+ it->str_value.set(*s, 0, s->length()); // store charset
+
it->res_type= val_item->result_type();
}
it->assigned(1);