Commit fc085d77 authored by unknown's avatar unknown

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.


mysql-test/r/sp-vars.result:
  Add result for bug#17226.
mysql-test/t/sp-vars.test:
  Add test case for bug#17226.
sql/field_conv.cc:
  Honor copy_blobs flag.
parent 9bbfa9fb
......@@ -1075,3 +1075,18 @@ SELECT f1();
f1()
abc
DROP FUNCTION f1;
DROP PROCEDURE IF EXISTS p1;
CREATE PROCEDURE p1()
BEGIN
DECLARE v_char VARCHAR(255);
DECLARE v_text TEXT DEFAULT '';
SET v_char = 'abc';
SET v_text = v_char;
SET v_char = 'def';
SET v_text = concat(v_text, '|', v_char);
SELECT v_text;
END|
CALL p1();
v_text
abc|def
DROP PROCEDURE p1;
......@@ -1271,3 +1271,39 @@ SELECT f1();
#
DROP FUNCTION f1;
#
# Bug#17226: Variable set in cursor on first iteration is assigned
# second iterations value
#
# The problem was in incorrect handling of local variables of type
# TEXT (BLOB).
#
--disable_warnings
DROP PROCEDURE IF EXISTS p1;
--enable_warnings
delimiter |;
CREATE PROCEDURE p1()
BEGIN
DECLARE v_char VARCHAR(255);
DECLARE v_text TEXT DEFAULT '';
SET v_char = 'abc';
SET v_text = v_char;
SET v_char = 'def';
SET v_text = concat(v_text, '|', v_char);
SELECT v_text;
END|
delimiter ;|
CALL p1();
DROP PROCEDURE p1;
# End of 5.0 tests.
......@@ -675,9 +675,14 @@ void field_conv(Field *to,Field *from)
{ // Be sure the value is stored
Field_blob *blob=(Field_blob*) to;
from->val_str(&blob->value);
if (!blob->value.is_alloced() &&
from->real_type() != MYSQL_TYPE_STRING &&
from->real_type() != MYSQL_TYPE_VARCHAR)
/*
Copy value if copy_blobs is set, or source is not a string and
we have a pointer to its internal string conversion buffer.
*/
if (to->table->copy_blobs ||
(!blob->value.is_alloced() &&
from->real_type() != MYSQL_TYPE_STRING &&
from->real_type() != MYSQL_TYPE_VARCHAR))
blob->value.copy();
blob->store(blob->value.ptr(),blob->value.length(),from->charset());
return;
......
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