-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Description
I have a very simple init sql script for MySQL that is provided to TC JDBC URL using TC_INITSCRIPT parameter -
drop table if exists books;
CREATE TABLE books (
book_id int(11) NOT NULL AUTO_INCREMENT,
title varchar(45) NOT NULL,
description varchar(45) NOT NULL,
price decimal(10,0) NOT NULL,
total_quantity int(11) NOT NULL,
available_quantity int(11) NOT NULL,
create_timestamp timestamp NULL DEFAULT NULL,
PRIMARY KEY (book_id)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE PROCEDURE calculate_library_value(out totalValue double)
BEGIN
select sum(price) into totalValue from books;
END;
When TestContainer starts, ScriptUtils class splits the statements by default ; delimiter. This results in last CREATE PROCEDURE statement to break after inline ; and the SQL Statement created by utils looks like below which is incorrect and hence fails
CREATE PROCEDURE calculate_library_value(out totalValue double)
BEGIN
select sum(price) into totalValue from books
Exception:
Caused by: org.testcontainers.jdbc.ext.ScriptUtils$ScriptStatementFailedException: Script execution failed (library_db.sql:3): CREATE PROCEDURE calculate_library_value(out totalValue double) BEGIN select sum(price) into totalValue from books
Possible solution:
When ; inside procedure are escaped \; then CREATE PROCEDURE block is read completely but again the execution of that SQL fails because ; is an invalid delimiter at runtime. Before executing the statement, should \; be replaced with ;?
Or I am doing it wrong?