MariaDB 10.2.13 CALL PROCEDURE PARAM LAST_INSERT_ID ()

You are viewing an old version of this article. View the current version here.

Before the update MariaDB 10.2.13 I was able to call a procedure inside the other passing as argument LAST_INSERT_ID (), now of the error in MariaDB, after the update I have to assign the LAST_INSERT_ID () in a variable before calling the procedure

Before MariaDB 10.2.13
in procedure1
CALL procedure2 (LAST_INSERT_ID ());


After MariaDB 10.2.13
in procedure1
SET id = LAST_INSERT_ID ();
CALL procedure2 (id);


Run CALL procedure1 ();

SET FOREIGN_KEY_CHECKS=0;

-- ----------------------------
--  Table structure for `table`
-- ----------------------------
DROP TABLE IF EXISTS `table`;
CREATE TABLE `table` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(20) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;

-- ----------------------------
--  Procedure definition for `procedure1`
-- ----------------------------
DROP PROCEDURE IF EXISTS `procedure1`;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `procedure1`()
MAIN:BEGIN
	DECLARE id INT(11) DEFAULT NULL;
	

	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE, @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
		SELECT @text AS message;
		ROLLBACK;
	END;

	START TRANSACTION;

		INSERT INTO `table` (name) VALUES ('Elvis');

		SET id = LAST_INSERT_ID();

		CALL procedure2(LAST_INSERT_ID());
	
		SELECT 'Add' AS message;

	COMMIT;		
END
;;
DELIMITER ;

-- ----------------------------
--  Procedure definition for `procedure2`
-- ----------------------------
DROP PROCEDURE IF EXISTS `procedure2`;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `procedure2`(IN id int(11))
BEGIN
	#Routine body goes here...

END
;;
DELIMITER ;

Comments

Comments loading...
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.