-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
SQL compound statement awareness in ScriptUtils #579
Conversation
modules/database-commons/src/main/java/org/testcontainers/ext/ScriptUtils.java
Show resolved
Hide resolved
ad24ba1
to
424141b
Compare
I don't think this fixes the problem, see my comment here: |
@bsideup @kiview I'd like to resurrect this PR, as it is a quick win to enable better SQL init scripts for JDBC containers. Issues such as #946 and #570 will continue to catch people out, which is silly when we have a solution that works well enough for typical usage. Please could you review? For reference init_mysql.sql shows the kinds of syntax that this PR enables, and is included in this PR for testing. |
@rnorth will do! |
modules/database-commons/src/main/java/org/testcontainers/ext/ScriptUtils.java
Outdated
Show resolved
Hide resolved
Prevents compound statements from being naively split by ScriptUtils
424141b
to
f56b399
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just had some style remarks, actual logic seems fine for the specified case.
modules/database-commons/src/main/java/org/testcontainers/ext/ScriptUtils.java
Show resolved
Hide resolved
modules/database-commons/src/main/java/org/testcontainers/ext/ScriptUtils.java
Outdated
Show resolved
Hide resolved
modules/database-commons/src/main/java/org/testcontainers/ext/ScriptUtils.java
Outdated
Show resolved
Hide resolved
6b5133b
to
6045dd3
Compare
modules/database-commons/src/main/java/org/testcontainers/ext/ScriptUtils.java
Outdated
Show resolved
Hide resolved
…ScriptUtils.java Co-Authored-By: rnorth <rich.north@gmail.com>
Released in 1.10.4! |
Thanks @rnorth, we ran into this issue with postgres a few weeks back. We will try it with latest version! |
Hi guys, I'm having some issues when using IF statement, it seems that it is assuming the word END in the "END IF" as the END of the BEGIN statement.
Instead of using the BEGIN - END block to ignore ;, I think the solution is to ignore ; whenever is inside |
This came out of #570. In brief, for DB init script handling,
ScriptUtils
is not capable of handling scripts that contain compound statements in stored procedures (BEGIN...END
sections). It will simply split the script on semicolons, mid-procedure, thus breaking the script.An example would be:
This prevents users from having stored procedures in their init scripts, which feels like an unpleasant limitation.
The Spring developers behind
ScriptUtils
chose not to go down the path of parsing the SQL, and I can see why they would do this. For arbitrary scripts and many SQL dialects, this could be quite open ended.However, I wonder if we can still improve on this just enough to be useful with a small change, so have created this WIP PR. I'm not intending for this to be the solution to all possible problems, but hope it unlocks us in some ways.
As-is, this:
I don't believe this could create any regressions in its current form, and I believe BEGIN/END support is all we need to improve things greatly.