Commit 24a0b385 authored by unknown's avatar unknown

Fix for BUG#18587: Function that accepts and returns TEXT

garbles data if longer than 766 chars.

The problem is that a stored routine returns BLOBs to the previous
caller, BLOBs are shallow-copied (i.e. only pointers to the data are
copied). The fix is to also copy data of BLOBs.


mysql-test/r/sp.result:
  Updated result file.
mysql-test/t/sp.test:
  Added a test case for BUG#18587.
sql/field_conv.cc:
  Do not jump to optimization if the field type is BLOB and
  the destination table requires copying of BLOBs.
sql/item_func.cc:
  Request copying BLOBs for the result table.
parent 38447ae8
......@@ -4929,4 +4929,35 @@ j
drop table t3|
drop view v1|
drop function bug12472|
DROP FUNCTION IF EXISTS bug18589_f1|
DROP PROCEDURE IF EXISTS bug18589_p1|
DROP PROCEDURE IF EXISTS bug18589_p2|
CREATE FUNCTION bug18589_f1(arg TEXT) RETURNS TEXT
BEGIN
RETURN CONCAT(arg, "");
END|
CREATE PROCEDURE bug18589_p1(arg TEXT, OUT ret TEXT)
BEGIN
SET ret = CONCAT(arg, "");
END|
CREATE PROCEDURE bug18589_p2(arg TEXT)
BEGIN
DECLARE v TEXT;
CALL bug18589_p1(arg, v);
SELECT v;
END|
SELECT bug18589_f1(REPEAT("a", 767))|
bug18589_f1(REPEAT("a", 767))
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa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DROP PROCEDURE bug18589_p2|
drop table t1,t2;
......@@ -5796,6 +5796,53 @@ drop view v1|
drop function bug12472|
#
# BUG#18587: Function that accepts and returns TEXT garbles data if longer than
# 766 chars
#
# Prepare.
--disable_warnings
DROP FUNCTION IF EXISTS bug18589_f1|
DROP PROCEDURE IF EXISTS bug18589_p1|
DROP PROCEDURE IF EXISTS bug18589_p2|
--enable_warnings
CREATE FUNCTION bug18589_f1(arg TEXT) RETURNS TEXT
BEGIN
RETURN CONCAT(arg, "");
END|
CREATE PROCEDURE bug18589_p1(arg TEXT, OUT ret TEXT)
BEGIN
SET ret = CONCAT(arg, "");
END|
CREATE PROCEDURE bug18589_p2(arg TEXT)
BEGIN
DECLARE v TEXT;
CALL bug18589_p1(arg, v);
SELECT v;
END|
# Test case.
SELECT bug18589_f1(REPEAT("a", 767))|
SET @bug18589_v1 = ""|
CALL bug18589_p1(REPEAT("a", 767), @bug18589_v1)|
SELECT @bug18589_v1|
CALL bug18589_p2(REPEAT("a", 767))|
# Cleanup.
DROP FUNCTION bug18589_f1|
DROP PROCEDURE bug18589_p1|
DROP PROCEDURE bug18589_p2|
#
# BUG#NNNN: New bug synopsis
#
......
......@@ -642,7 +642,8 @@ void (*Copy_field::get_copy_func(Field *to,Field *from))(Copy_field*)
void field_conv(Field *to,Field *from)
{
if (to->real_type() == from->real_type())
if (to->real_type() == from->real_type() &&
!(to->type() == FIELD_TYPE_BLOB && to->table->copy_blobs))
{
if (to->pack_length() == from->pack_length() &&
!(to->flags & UNSIGNED_FLAG && !(from->flags & UNSIGNED_FLAG)) &&
......
......@@ -4735,6 +4735,7 @@ Item_func_sp::sp_result_field(void) const
dummy_table->alias = empty_name;
dummy_table->maybe_null = maybe_null;
dummy_table->in_use= current_thd;
dummy_table->copy_blobs= TRUE;
share->table_cache_key = empty_name;
share->table_name = empty_name;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment