Commit 65b87b86 authored by anozdrin@mysql.com's avatar anozdrin@mysql.com

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.
parent 247be7d4
...@@ -4929,4 +4929,35 @@ j ...@@ -4929,4 +4929,35 @@ j
drop table t3| drop table t3|
drop view v1| drop view v1|
drop function bug12472| 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))
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa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,6 +5796,53 @@ drop view v1|
drop function bug12472| 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 # BUG#NNNN: New bug synopsis
# #
......
...@@ -642,7 +642,8 @@ void (*Copy_field::get_copy_func(Field *to,Field *from))(Copy_field*) ...@@ -642,7 +642,8 @@ void (*Copy_field::get_copy_func(Field *to,Field *from))(Copy_field*)
void field_conv(Field *to,Field *from) 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() && if (to->pack_length() == from->pack_length() &&
!(to->flags & UNSIGNED_FLAG && !(from->flags & UNSIGNED_FLAG)) && !(to->flags & UNSIGNED_FLAG && !(from->flags & UNSIGNED_FLAG)) &&
......
...@@ -4735,6 +4735,7 @@ Item_func_sp::sp_result_field(void) const ...@@ -4735,6 +4735,7 @@ Item_func_sp::sp_result_field(void) const
dummy_table->alias = empty_name; dummy_table->alias = empty_name;
dummy_table->maybe_null = maybe_null; dummy_table->maybe_null = maybe_null;
dummy_table->in_use= current_thd; dummy_table->in_use= current_thd;
dummy_table->copy_blobs= TRUE;
share->table_cache_key = empty_name; share->table_cache_key = empty_name;
share->table_name = 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