Quantcast
Channel: MySQL Forums - Connector/J, JDBC and Java
Viewing all articles
Browse latest Browse all 884

Procedure runs fine in DB but throwing errors while running within integration tests (2 replies)

$
0
0
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;

Viewing all articles
Browse latest Browse all 884

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>