You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Ignore comments when searching for statement delimiter in ScriptUtils
Prior to this commit, the implementation of
ScriptUtils.containsSqlScriptDelimiters() did not ignore comments when
searching for the statement delimiter within an SQL script. This
resulted in subtle bugs if a comment contained a single single-quote or
single double-quote, since the absence of the closing single-quote or
double-quote led the algorithm to believe that it was still "within a
text literal". Similar issues could arise if a comment contained the
sought statement delimiter but the rest of the script did not contain
the sought statement delimiter. In such cases, the algorithms in
ScriptUtils could erroneously choose an incorrect statement delimiter
-- for example, using the fallback statement delimiter instead of the
delimiter specified by the user.
This commit avoids such bugs by ignoring single-line comments and block
comments when searching for the statement delimiter within an SQL
script.
Closesgh-26911
Copy file name to clipboardExpand all lines: spring-jdbc/src/test/resources/org/springframework/jdbc/datasource/init/test-data-with-multi-line-nested-comments.sql
+4-1Lines changed: 4 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -5,16 +5,19 @@
5
5
* x, y, z...
6
6
*/
7
7
8
+
-- This is a single line comment containing single (') and double quotes (").
8
9
INSERT INTO users(first_name, last_name) VALUES('Juergen', 'Hoeller');
9
10
-- This is also a comment.
10
11
/*-------------------------------------------
11
-
-- A fancy multi-line comments that puts
12
+
-- A fancy multi-line comment that puts
12
13
-- single line comments inside of a multi-line
13
14
-- comment block.
14
15
Moreover, the block comment end delimiter
15
16
appears on a line that can potentially also
16
17
be a single-line comment if we weren't
17
18
already inside a multi-line comment run.
19
+
20
+
And here's a line containing single and double quotes (").
18
21
-------------------------------------------*/
19
22
INSERT INTO
20
23
users(first_name, last_name) -- This is a single line comment containing the block-end-comment sequence here */ but it's still a single-line comment
0 commit comments