Skip to content

Commit 96bddca

Browse files
author
kroki@mysql.com
committed
Bug#17226: Variable set in cursor on first iteration is assigned
second iterations value During assignment to the BLOB variable in routine body the value wasn't copied.
1 parent 21e1655 commit 96bddca

File tree

3 files changed

+59
-3
lines changed

3 files changed

+59
-3
lines changed

mysql-test/r/sp-vars.result

+15
Original file line numberDiff line numberDiff line change
@@ -1075,3 +1075,18 @@ SELECT f1();
10751075
f1()
10761076
abc
10771077
DROP FUNCTION f1;
1078+
DROP PROCEDURE IF EXISTS p1;
1079+
CREATE PROCEDURE p1()
1080+
BEGIN
1081+
DECLARE v_char VARCHAR(255);
1082+
DECLARE v_text TEXT DEFAULT '';
1083+
SET v_char = 'abc';
1084+
SET v_text = v_char;
1085+
SET v_char = 'def';
1086+
SET v_text = concat(v_text, '|', v_char);
1087+
SELECT v_text;
1088+
END|
1089+
CALL p1();
1090+
v_text
1091+
abc|def
1092+
DROP PROCEDURE p1;

mysql-test/t/sp-vars.test

+36
Original file line numberDiff line numberDiff line change
@@ -1271,3 +1271,39 @@ SELECT f1();
12711271
#
12721272

12731273
DROP FUNCTION f1;
1274+
1275+
1276+
#
1277+
# Bug#17226: Variable set in cursor on first iteration is assigned
1278+
# second iterations value
1279+
#
1280+
# The problem was in incorrect handling of local variables of type
1281+
# TEXT (BLOB).
1282+
#
1283+
--disable_warnings
1284+
DROP PROCEDURE IF EXISTS p1;
1285+
--enable_warnings
1286+
1287+
delimiter |;
1288+
CREATE PROCEDURE p1()
1289+
BEGIN
1290+
DECLARE v_char VARCHAR(255);
1291+
DECLARE v_text TEXT DEFAULT '';
1292+
1293+
SET v_char = 'abc';
1294+
1295+
SET v_text = v_char;
1296+
1297+
SET v_char = 'def';
1298+
1299+
SET v_text = concat(v_text, '|', v_char);
1300+
1301+
SELECT v_text;
1302+
END|
1303+
delimiter ;|
1304+
1305+
CALL p1();
1306+
1307+
DROP PROCEDURE p1;
1308+
1309+
# End of 5.0 tests.

sql/field_conv.cc

+8-3
Original file line numberDiff line numberDiff line change
@@ -675,9 +675,14 @@ void field_conv(Field *to,Field *from)
675675
{ // Be sure the value is stored
676676
Field_blob *blob=(Field_blob*) to;
677677
from->val_str(&blob->value);
678-
if (!blob->value.is_alloced() &&
679-
from->real_type() != MYSQL_TYPE_STRING &&
680-
from->real_type() != MYSQL_TYPE_VARCHAR)
678+
/*
679+
Copy value if copy_blobs is set, or source is not a string and
680+
we have a pointer to its internal string conversion buffer.
681+
*/
682+
if (to->table->copy_blobs ||
683+
(!blob->value.is_alloced() &&
684+
from->real_type() != MYSQL_TYPE_STRING &&
685+
from->real_type() != MYSQL_TYPE_VARCHAR))
681686
blob->value.copy();
682687
blob->store(blob->value.ptr(),blob->value.length(),from->charset());
683688
return;

0 commit comments

Comments
 (0)