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. |
…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]>
Co-authored-by: Eddú Meléndez <[email protected]> Co-authored-by: Kevin Wittek <[email protected]>
…L identifiers (as introduced by testcontainers#7646) (testcontainers#7818) Co-authored-by: Eddú Meléndez Gonzales <[email protected]>
Fix #3316
Fix #4441
Problem
Current version of
ScriptUtils.splitSqlScripttries to take into accountBEGIN...ENDblocks. However, it treats anyENDas an end of the block, even if it'sEND IForEND 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
GOin 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 moreENDs thanBEGINs 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
ENDimmediately followed by a separator (with probably whitespace and/or comments preceding the separator).The current implementation of
splitSqlScriptis 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
ScriptScannerclass. This class retrieves next id, next comment, next string literal etc.2 "Syntactic rules" are implemented in
ScriptSplitterwhis is just a recursive procedural parser.