-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
fix bug in splitSqlScript #7646
Conversation
Hey @inponomarev, thanks for your PR, but unfortunately we will have to close it.
Instead, we recommend to use the mechanisms provided by the vendor specific images, which mostly means using In the future, we'd suggest to reach out to us first via Slack or GH discussions, to avoid unnecessary work on features that won't get merged. |
Re-opened after private discussion in Slack. |
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.
Can you PTAL @eddumelendez?
modules/database-commons/src/main/java/org/testcontainers/ext/ScriptScanner.java
Outdated
Show resolved
Hide resolved
…ScriptScanner.java Co-authored-by: Kevin Wittek <[email protected]>
Thanks for your contribution, @inponomarev ! |
…L identifiers (as introduced by #7646) (#7818) Co-authored-by: Eddú Meléndez Gonzales <[email protected]>
Fix #3316
Fix #4441
Problem
Current version of
ScriptUtils.splitSqlScript
tries to take into accountBEGIN...END
blocks. However, it treats anyEND
as an end of the block, even if it'sEND IF
orEND LOOP
, so that the following one-statement scriptBEGIN rec_loop: LOOP FETCH blah; IF something_wrong THEN LEAVE rec_loop; END IF; do_something_else; END LOOP; END;
Is incorrectly split into following "statements":
This is also broken for the case when a special statement separator is used (like
GO
in MSSQL tradition,/
in Oracle tradition or@
in DB2).The following statement is not split over
@
sign as when it comes to the separator, the algorithm counted moreEND
s thanBEGIN
s and and since the balance is not zero, it is not splitting the code:BEGIN rec_loop: LOOP FETCH blah; IF something_wrong THEN LEAVE rec_loop; END IF; do_something_else; END LOOP; END; @ CALL something(); @
Solution
Apparently, the "true end of block" must be
END
immediately followed by a separator (with probably whitespace and/or comments preceding the separator).The current implementation of
splitSqlScript
is poorly written and it's difficult to extend "syntax rules". So I have completely rewritten it in a style of a standard parser:1 "Lexical analysis" is perfromed in
ScriptScanner
class. This class retrieves next id, next comment, next string literal etc.2 "Syntactic rules" are implemented in
ScriptSplitter
whis is just a recursive procedural parser.