Bug #8627 When fetching empty string from cursor into variable, server crashes
Submitted: 19 Feb 2005 17:04 Modified: 19 Feb 2005 17:37
Reporter: Gabor Bereczki Email Updates:
Status: Can't repeat Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:5.0.0 OS:Linux (linux x86_64)
Assigned to: CPU Architecture:Any

[19 Feb 2005 17:04] Gabor Bereczki
Description:
I created a stored procedure and fetched records containing only text columns from a table into 
text variables. all goes OK until it hits a NULL or "" empty string value. Then the server crashes.

How to repeat:
CREATE TABLE test_table (col1 VARCHAR(7),col2 TEXT);

REATE PROCEDURE  testproc()
BEGIN
DECLARE cur1 CURSOR FOR SELECT col1, col2 FROM test_table;
DECLARE v_col1 VARCHAR(7);
DECLARE v_col2 TEXT;
DELETE FROM test_table;
INSERT INTO test_table ( col1, col2 ) values ( '1', '');
OPEN cur1;
FETCH cur1 INTO v_col1, v_col2;
CLOSE cur1;
END

CALL testproc();

the result is:
mysqld got signal 11;
This could be because you hit a bug. It is also possible that this binary
or one of the libraries it was linked against is corrupt, improperly built,
or misconfigured. This error can also be caused by malfunctioning hardware.
We will try our best to scrape up some info that will hopefully help diagnose
the problem, but since we have already crashed, something is definitely wrong
and this may fail.

key_buffer_size=8388600
read_buffer_size=131072
max_used_connections=1
max_connections=100
threads_connected=2
It is possible that mysqld could use up to
key_buffer_size + (read_buffer_size + sort_buffer_size)*max_connections = 225791 K
bytes of memory
Hope that's ok; if not, decrease some variables in the equation.
:

However if you replace the empty string in the INSERT INTO statament the server wont crash.

Suggested fix:
Got no clue.
[19 Feb 2005 17:26] Gabor Bereczki
Sorry, now I installed 5.0.1 and now I am getting intelligible compile time error messages. This one was caused by cursor declaration before variable declarations.
[19 Feb 2005 17:37] MySQL Verification Team
Tested against latest BK source on Slackware 10.0

mysql> CREATE TABLE test_table (col1 VARCHAR(7),col2 TEXT);
Query OK, 0 rows affected (0.00 sec)

mysql> DELIMITER //
mysql> CREATE PROCEDURE  testproc()
    -> BEGIN
    -> DECLARE v_col1 VARCHAR(7);
    -> DECLARE v_col2 TEXT;
    -> DECLARE cur1 CURSOR FOR SELECT col1, col2 FROM test_table;
    -> DELETE FROM test_table;
    -> INSERT INTO test_table ( col1, col2 ) values ( '1', '');
    -> OPEN cur1;
    -> FETCH cur1 INTO v_col1, v_col2;
    -> CLOSE cur1;
    -> END//
Query OK, 0 rows affected (0.00 sec)

mysql> DELIMITER ;
mysql> CALL testproc();
Query OK, 0 rows affected (0.01 sec)

mysql> SELECT * FROM test_table;
+------+------+
| col1 | col2 |
+------+------+
| 1    |      |
+------+------+
1 row in set (0.00 sec)

mysql> SELECT version();
+-------------------+
| version()         |
+-------------------+
| 5.0.3-alpha-debug |
+-------------------+
1 row in set (0.01 sec)

mysql>