Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ScriptUtils.containsSqlScriptDelimiters does not take into account escaped quotes [SPR-17120] #21657

Closed
spring-projects-issues opened this issue Aug 2, 2018 · 6 comments
Assignees
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Aug 2, 2018

geordiecoder opened SPR-17120 and commented

ScriptUtils#containsSqlScriptDelimiters() does not take into account escaped quotes when looking for delimiters in the script.

The delimiter in the following example won't be found, since the method gets out of step with the literals. The result being the fallback delimiter "\n" being used, breaking the script (since ScriptUtils will attempt to execute just the first line):

INSERT INTO some_table (id, val)
VALUES
   (1,'this won\'t work');

Edit: This happens with a MySQL database. With HSQLDB I believe you can't escape quotes in this way, but rather with a second quote, which wouldn't exhibit the problem. If ScriptUtils is only meant to be used with HSQLDB then apologies, and please close this!


Reference URL: #1919

Referenced from: commits bdac391, 24ed6de

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Aug 7, 2018

Sam Brannen commented

Edit: This happens with a MySQL database. With HSQLDB I believe you can't escape quotes in this way, but rather with a second quote, which wouldn't exhibit the problem. If ScriptUtils is only meant to be used with HSQLDB then apologies, and please close this!

ScriptUtils is not limited to use with embedded databases such as H2 or HSQLDB. In general we try to make ScriptUtils usable with most mainstream relational databases, whenever feasible.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Aug 7, 2018

Sam Brannen commented

PR submitted: #1919

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Aug 7, 2018

Sam Brannen commented

FYI: we already have explicit handling of MySQL syntax here in splitSqlScript():

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

So, I'd say the lack of a similar check in containsSqlScriptDelimiters() was merely an oversight.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Aug 7, 2018

Sam Brannen commented

Tentatively slated for 5.1 RC2.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Aug 7, 2018

geordiecoder commented

Good point about splitSqlScript() - I should have looked at that first!

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Aug 13, 2018

Sam Brannen commented

The PR has been merged into master in 24ed6de and further refined in bdac391.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.