Procedure runs fine in DB but throwing errors while running within integration tests
Posted by: Ishan Jain
Date: June 05, 2023 02:32AM

I have the below procedure which I wanted to run before each test in my application integration tests to quickly truncate all tables in my schema:
But this does not work in integration test run while it runs fine in a DB


DELIMITER //
CREATE PROCEDURE truncate_tables()
BEGIN
DECLARE tblName CHAR(200);
DECLARE done INT DEFAULT FALSE;
DECLARE dbTables CURSOR FOR
SELECT table_name
FROM information_schema.tables
WHERE table_schema = (SELECT DATABASE());
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;

OPEN dbTables;
SET FOREIGN_KEY_CHECKS = 0;

read_loop: LOOP
FETCH dbTables INTO tblName;
IF done THEN
LEAVE read_loop;
END IF;
SET @s = CONCAT('TRUNCATE TABLE ', tblName);
PREPARE stmt FROM @s;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
END LOOP read_loop;

CLOSE dbTables;
SET FOREIGN_KEY_CHECKS = 1;
END
//

CALL truncate_tables();
DROP PROCEDURE IF EXISTS truncate_tables;

Options: ReplyQuote


Subject
Written By
Posted
Procedure runs fine in DB but throwing errors while running within integration tests
June 05, 2023 02:32AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.