Skip to content

Support triggers & stored procedures alongside standard statements in SQL scripts [SPR-13389] #17970

@spring-projects-issues

Description

@spring-projects-issues

Amol Khanolkar opened SPR-13389 and commented

Status Quo

In the current version of Spring we cannot execute an SQL script like the following if the script also contains standard SQL statements (e.g., INSERT, DELETE, etc.), because nested semicolons in the trigger declaration are interpreted as the default statement separator.

CREATE TRIGGER {TriggerNameName}
	BEFORE INSERT ON  {TableName} 
		FOR EACH ROW BEGIN 
			SET NEW.date_modified = CURTIME(6);
			SET NEW.modified_by = USER(); 
		END;

We can easily fix this by escaping the semicolons within the trigger declaration like this:

CREATE TRIGGER {TriggerNameName}
	BEFORE INSERT ON  {TableName} 
		FOR EACH ROW BEGIN 
			SET NEW.date_modified = CURTIME(6)\;
			SET NEW.modified_by = USER()\; 
		END\; ;

Proposal

Actually I see the following snippet in the source code for ScriptUtils:

if (inEscape) {
	inEscape = false;
	sb.append(c);
	continue;
}
// MySQL style escapes
if (c == '\\') {
	inEscape = true;
	sb.append(c);
	continue;
}

Modifying as follows fixes the issue. I am not sure why in original code Escape String was appended to the StringBuffer.

if (inEscape) {
	inEscape = false;
	sb.append(c);
	continue;
}
// MySQL style escapes
if (c == '\\') {
	inEscape = true;
	continue;
}

Affects: 4.1.7

Issue Links:

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