[MDEV-30079] MySql - Bug 28227 - Cursor fetches null values into variables Created: 2022-11-23  Updated: 2022-11-25

Status: Open
Project: MariaDB Server
Component/s: Data Definition - Procedure
Affects Version/s: 10.4.27
Fix Version/s: None

Type: Bug Priority: Major
Reporter: Carlos Oliveira Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None
Environment:

AWS RDS - 10.4.26-MariaDB-log


Attachments: File MDEV-30079_Script_to_reproduce.sql    

 Description   

Also reported as mysql bug => https://bugs.mysql.com/bug.php?id=28227

When using cursor/fetch procedure, the variables became empty when they have same name as table column name.

The code below can reproduce it:
Does not work => CUSTOMER_NAME variable
Works fine => V_CUSTOMER_NAME variable

CREATE TEMPORARY TABLE TMP_TEST1 (CUSTOMER_NAME varchar(255));
INSERT INTO TMP_TEST1 (CUSTOMER_NAME) 
VALUES ('JOHN'),('MIKE'),('SMITH');
 
DELIMITER //
BEGIN NOT ATOMIC
 
  DECLARE done INT DEFAULT FALSE;
  -- DECLARE CUSTOMER_NAME varchar(255); -- not works
  DECLARE V_CUSTOMER_NAME varchar(255); -- works
  DECLARE CUSTOMER_NAME_LIST text DEFAULT '';
  DECLARE cur1 CURSOR FOR SELECT CUSTOMER_NAME FROM TMP_TEST1;
  DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
  
  OPEN cur1;
  read_loop: LOOP
    -- FETCH cur1 INTO CUSTOMER_NAME; -- not works
    FETCH cur1 INTO V_CUSTOMER_NAME; -- works
    IF done THEN
      LEAVE read_loop;
    END IF;
    -- set CUSTOMER_NAME_LIST = CONCAT_WS('|',CUSTOMER_NAME_LIST,CUSTOMER_NAME); -- not works
    set CUSTOMER_NAME_LIST = CONCAT_WS('|',CUSTOMER_NAME_LIST,V_CUSTOMER_NAME); -- works
  END LOOP read_loop;
  CLOSE cur1;
 
  SELECT CUSTOMER_NAME_LIST;
  
END; //
DELIMITER ;
 
DROP TEMPORARY TABLE TMP_TEST1;


Generated at Thu Feb 08 10:13:29 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.