summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <konstantin@mysql.com>2004-09-23 18:01:55 +0400
committerunknown <konstantin@mysql.com>2004-09-23 18:01:55 +0400
commitedcccfbc4b71152af849f53fc3760a05e1e0d4bb (patch)
tree2deae2cf9d86f0f0b7e370d20237a5287f1d7dbe
parent3f76fd69a454176dde8264c1ac4e676e92e28fdf (diff)
downloadmariadb-git-edcccfbc4b71152af849f53fc3760a05e1e0d4bb.tar.gz
A fix and test case for bug#5688 "Upgraded 4.1.5 Server seg faults"
mysql-test/r/ps.result: Test results fixed: the test case for bug#5688 "Upgraded 4.1.5 Server seg faults" mysql-test/t/ps.test: Test case for bug#5688 "Upgraded 4.1.5 Server seg faults" sql/item_cmpfunc.cc: A fix for bug#5688 "Upgraded 4.1.5 Server seg faults": fix just another place where we use wrong memory root for an Item in statement prepare. In addition, make the check for charsets in Item_bool_func2 more generic (fixes the test case when we use LIKE to compare BLOBs with TEXT data).
-rw-r--r--mysql-test/r/ps.result8
-rw-r--r--mysql-test/t/ps.test10
-rw-r--r--sql/item_cmpfunc.cc26
3 files changed, 32 insertions, 12 deletions
diff --git a/mysql-test/r/ps.result b/mysql-test/r/ps.result
index 8742ac29989..12337d358e1 100644
--- a/mysql-test/r/ps.result
+++ b/mysql-test/r/ps.result
@@ -289,3 +289,11 @@ execute stmt using @var;
select * from t1;
deallocate prepare stmt;
drop table t1;
+prepare stmt from "select 'abc' like convert('abc' using utf8)";
+execute stmt;
+'abc' like convert('abc' using utf8)
+1
+execute stmt;
+'abc' like convert('abc' using utf8)
+1
+deallocate prepare stmt;
diff --git a/mysql-test/t/ps.test b/mysql-test/t/ps.test
index af356ca2a09..4b63a7db95f 100644
--- a/mysql-test/t/ps.test
+++ b/mysql-test/t/ps.test
@@ -304,3 +304,13 @@ select * from t1;
deallocate prepare stmt;
drop table t1;
+#
+# BUG#5688 "Upgraded 4.1.5 Server seg faults" # (prepared statements)
+# The test case speaks for itself.
+# Just another place where we used wrong memory root for Items created
+# during statement prepare.
+#
+prepare stmt from "select 'abc' like convert('abc' using utf8)";
+execute stmt;
+execute stmt;
+deallocate prepare stmt;
diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc
index 85b22d1eddd..8950ad0c594 100644
--- a/sql/item_cmpfunc.cc
+++ b/sql/item_cmpfunc.cc
@@ -188,17 +188,27 @@ void Item_bool_func2::fix_length_and_dec()
{
uint strong= 0;
uint weak= 0;
+ uint32 dummy_offset;
DTCollation coll;
if (args[0]->result_type() == STRING_RESULT &&
args[1]->result_type() == STRING_RESULT &&
- !my_charset_same(args[0]->collation.collation,
- args[1]->collation.collation) &&
+ String::needs_conversion(0, args[0]->collation.collation,
+ args[1]->collation.collation,
+ &dummy_offset) &&
!coll.set(args[0]->collation, args[1]->collation, TRUE))
{
Item* conv= 0;
+ THD *thd= current_thd;
+ Item_arena *arena= thd->current_arena, backup;
strong= coll.strong;
weak= strong ? 0 : 1;
+ /*
+ In case we're in statement prepare, create conversion item
+ in its memory: it will be reused on each execute.
+ */
+ if (arena->is_stmt_prepare())
+ thd->set_n_backup_item_arena(arena, &backup);
if (args[weak]->type() == STRING_ITEM)
{
String tmp, cstr;
@@ -211,21 +221,13 @@ void Item_bool_func2::fix_length_and_dec()
}
else
{
- THD *thd= current_thd;
- /*
- In case we're in statement prepare, create conversion item
- in its memory: it will be reused on each execute.
- */
- Item_arena *arena= thd->current_arena, backup;
- if (arena->is_stmt_prepare())
- thd->set_n_backup_item_arena(arena, &backup);
conv= new Item_func_conv_charset(args[weak],
args[strong]->collation.collation);
- if (arena->is_stmt_prepare())
- thd->restore_backup_item_arena(arena, &backup);
conv->collation.set(args[weak]->collation.derivation);
conv->fix_fields(thd, 0, &conv);
}
+ if (arena->is_stmt_prepare())
+ thd->restore_backup_item_arena(arena, &backup);
args[weak]= conv ? conv : args[weak];
}
}