Skip to content

Support per-script statement separator configuration for SQL scripts [SPR-8817] #13459

@spring-projects-issues

Description

@spring-projects-issues

Julian Sareyka opened SPR-8817 and commented

I have tried to setup an in-memory db with hsql. In one of my scripts there is a stored procedure. Database setup fails when executing this script.

I found out that this is due to automatic statement splitting in ResourceDatabasePopulator. Here all statements in a script are split on semicolons. So my stored procedure is cut into pieces (after p_date_value DAY;).

CREATE FUNCTION pkg_verweildauer.get_pub_ende (IN p_pub_start TIMESTAMP, IN p_date_unit VARCHAR(255), IN p_date_value NUMERIC) 
RETURNS timestamp
READS SQL DATA
BEGIN ATOMIC

DECLARE v_pub_ende timestamp;
case p_date_unit
	when 'DAYS' then
		SET v_pub_ende = p_pub_start + p_date_value DAY;
	when 'WEEKS' then
		SET v_pub_ende = TIMESTAMPADD(SQL_TSI_WEEK, p_date_value, p_pub_start);
	when 'MONTHS' then
		SET v_pub_ende = TIMESTAMPADD(SQL_TSI_MONTH, p_date_value, p_pub_start);
	when 'YEARS' then
		SET v_pub_ende = TIMESTAMPADD(SQL_TSI_YEAR, p_date_value, p_pub_start);
	else
		SET v_pub_ende = p_pub_start + 365 DAY;
end case;
RETURN v_pub_ende;

END;

A simple solution would be to add a parameter to the <jdbc:script> tag to disable splitting on file basis. Unfortunately ResourceDatabasePopulator cannot be exchanged in the EmbeddedDatabaseBuilder.

I had to write a post processing bean, to add the stored function.


Affects: 3.0.5

Issue Links:

3 votes, 2 watchers

Metadata

Metadata

Assignees

Labels

in: dataIssues in data modules (jdbc, orm, oxm, tx)status: declinedA suggestion or change that we don't feel we should currently applytype: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions