Bug #16888 Cursor fails to FETCH
Submitted: 29 Jan 2006 23:50 Modified: 30 Jan 2006 11:30
Reporter: Ian Gulliver Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:5.1.5-alpha-max OS:Linux (Debian Etch)
Assigned to: CPU Architecture:Any

[29 Jan 2006 23:50] Ian Gulliver
Description:
When a cursor column is fetched into a procedure-level variable with the same name as the column, it always fetches NULL.  Otherwise, the cursor seems to work normally (fetches the right number of rows, etc.).  Simply changing the column or variable names fixes the issue.

How to repeat:
delimiter //

DROP TABLE IF EXISTS test//
CREATE TABLE test (c INT)//
INSERT INTO test VALUES (5)//

DROP PROCEDURE IF EXISTS bugproc//
CREATE PROCEDURE bugproc ()
        BEGIN
                DECLARE c INT;
                DECLARE cur1 CURSOR FOR SELECT c FROM test;

                OPEN cur1;

                FETCH cur1 INTO c;

                SELECT c;

                CLOSE cur1;
        END//

CALL bugproc//
[30 Jan 2006 0:29] Jorge del Conde
Thanks for your bug report.  I was able to reproduce this under 5.0 and 5.1

mysql> call bugproc();
    -> //
+------+
| c    |
+------+
| NULL |
+------+
1 row in set (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

mysql>
[30 Jan 2006 11:30] Per-Erik Martin
This is a dubplicate  of BUG#5967.