-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Closed
Labels
in: dataIssues in data modules (jdbc, orm, oxm, tx)Issues in data modules (jdbc, orm, oxm, tx)status: declinedA suggestion or change that we don't feel we should currently applyA suggestion or change that we don't feel we should currently applytype: enhancementA general enhancementA general enhancement
Description
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:
- Support per-script statement separator configuration for SQL scripts [SPR-8817] #13459 Support per-script statement separator configuration for SQL scripts
- Support EOF as statement separator in SQL scripts [SPR-11687] #16310 Support EOF as statement separator in SQL scripts
Metadata
Metadata
Assignees
Labels
in: dataIssues in data modules (jdbc, orm, oxm, tx)Issues in data modules (jdbc, orm, oxm, tx)status: declinedA suggestion or change that we don't feel we should currently applyA suggestion or change that we don't feel we should currently applytype: enhancementA general enhancementA general enhancement