Skip to content

Commit

Permalink
Improved handling of endDelimiter="/" (#3118)
Browse files Browse the repository at this point in the history
If delimiter is "/", only count it as a delimiter if it is at the beginning of a line. Not in the middle and likely a division sign
  • Loading branch information
nvoxland committed Aug 1, 2022
1 parent abcd08f commit e3f2d2c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
3 changes: 2 additions & 1 deletion liquibase-core/src/main/java/liquibase/util/StringUtil.java
Expand Up @@ -176,7 +176,8 @@ protected static boolean isDelimiter(String piece, String previousPiece, String
} else {
if (endDelimiter.length() == 1) {
if ("/".equals(endDelimiter)) {
if (previousPiece != null && previousPiece.endsWith("*")) {
if (previousPiece != null && !previousPiece.endsWith("\n")) {
//don't count /'s the are there for comments for division signs or any other use besides a / at the beginning of a line
return false;
}
}
Expand Down
Expand Up @@ -165,9 +165,12 @@ END reany_procedure_name;
grant /*Beware, this comment should not be seen as a delimiter! */
execute on any_procedure_name to ANY_USER1/
grant execute on any_procedure_name to ANY_USER2/
grant execute on any_procedure_name to ANY_USER3/
execute on any_procedure_name to ANY_USER1
/
grant execute on any_procedure_name to ANY_USER2
/
grant execute on any_procedure_name to ANY_USER3
/
-- rollback drop PROCEDURE refresh_all_fos_permission_views/
"""

Expand Down Expand Up @@ -695,13 +698,14 @@ not ignoreLines here
changeLog.getChangeSets().size() == 1
changeLog.getChangeSets().get(0).getChanges().size() == 1
def statements = changeLog.getChangeSets().get(0).getChanges().get(0).generateStatements(new MockDatabase())
statements.size() == 4
statements[0].toString() == "CREATE OR REPLACE PROCEDURE any_procedure_name is\nBEGIN\n" +
statements*.toString() == [
"CREATE OR REPLACE PROCEDURE any_procedure_name is\nBEGIN\n" +
" DBMS_MVIEW.REFRESH('LEAD_INST_FOS_MV', method => '?', atomic_refresh => FALSE, out_of_place => true);\n" +
"END reany_procedure_name;"
statements[1].toString() == "grant \n execute on any_procedure_name to ANY_USER1"
statements[2].toString() == "grant execute on any_procedure_name to ANY_USER2"
statements[3].toString() == "grant execute on any_procedure_name to ANY_USER3"
"END reany_procedure_name;",
"grant \n execute on any_procedure_name to ANY_USER1",
"grant execute on any_procedure_name to ANY_USER2",
"grant execute on any_procedure_name to ANY_USER3",
]
}

@Unroll("#featureName: #example")
Expand Down
Expand Up @@ -24,9 +24,14 @@ class StringUtilTest extends Specification {
true | true | null | "/*\nThis is a test comment of SQL script\n*/\n\nSelect * from Test;\nUpdate Test set field = 1" | ["Select * from Test", "Update Test set field = 1"]
true | true | null | "select * from simple_select_statement;\ninsert into table ( col ) values (' value with; semicolon ');" | ["select * from simple_select_statement", "insert into table ( col ) values (' value with; semicolon ')"]
true | true | null | "--\n-- Create the blog table.\n--\nCREATE TABLE blog\n(\n ID NUMBER(15) NOT NULL\n)" | ["CREATE TABLE blog\n(\n ID NUMBER(15) NOT NULL\n)"]
true | true | null | "statement 1/2\n/\nstatement 2/2" | ["statement 1/2", "statement 2/2"]
true | true | "//" | "drop procedure if exists my_proc//\n\ncreate procedure my_proc(i_myvar varchar)\nbegin\n a bunch of code here\nend//" | ["drop procedure if exists my_proc", "create procedure my_proc(i_myvar varchar)\nbegin\n a bunch of code here\nend"]
true | true | "/" | "CREATE OR REPLACE PACKAGE emp_actions AS -- spec\nTYPE EmpRecTyp IS RECORD (emp_id INT, salary REAL);\nCURSOR desc_salary RETURN EmpRecTyp);\nEND emp_actions;" | ["CREATE OR REPLACE PACKAGE emp_actions AS \nTYPE EmpRecTyp IS RECORD (emp_id INT, salary REAL);\nCURSOR desc_salary RETURN EmpRecTyp);\nEND emp_actions;"]
true | true | "/" | "CREATE OR REPLACE PACKAGE emp_actions AS -- spec\nTYPE EmpRecTyp IS RECORD (emp_id INT, salary REAL);\nCURSOR desc_salary RETURN EmpRecTyp);\nEND emp_actions;\n/\nanother statement;here\n/\n" | ["CREATE OR REPLACE PACKAGE emp_actions AS \nTYPE EmpRecTyp IS RECORD (emp_id INT, salary REAL);\nCURSOR desc_salary RETURN EmpRecTyp);\nEND emp_actions;", "another statement;here"]
true | true | "/" | "statement 1/2\n/\nstatement 2/2" | ["statement 1/2", "statement 2/2"]
true | true | "/" | "/* a comment here */ statement 1/2\n/\nstatement 2/2" | ["statement 1/2", "statement 2/2"]
false | true | "/" | "/* a comment here */ statement 1/2\n/\nstatement 2/2" | ["/* a comment here */ statement 1/2", "statement 2/2"]
true | true | "/" | "/\nstatement here" | ["statement here"]
true | true | "\\n/" | "CREATE OR REPLACE PACKAGE emp_actions AS -- spec\nTYPE EmpRecTyp IS RECORD (emp_id INT, salary REAL);\nCURSOR desc_salary RETURN EmpRecTyp);\nEND emp_actions;\n/\nanother statement;here\n/\n" | ["CREATE OR REPLACE PACKAGE emp_actions AS \nTYPE EmpRecTyp IS RECORD (emp_id INT, salary REAL);\nCURSOR desc_salary RETURN EmpRecTyp);\nEND emp_actions;", "another statement;here"]
true | true | "\\ngo" | "CREATE OR REPLACE PACKAGE emp_actions AS -- spec\nTYPE EmpRecTyp IS RECORD (emp_id INT, salary REAL);\nCURSOR desc_salary RETURN EmpRecTyp);\nEND emp_actions;\nGO\nanother statement;here\nGO\n" | ["CREATE OR REPLACE PACKAGE emp_actions AS \nTYPE EmpRecTyp IS RECORD (emp_id INT, salary REAL);\nCURSOR desc_salary RETURN EmpRecTyp);\nEND emp_actions;", "another statement;here"]
true | true | null | "statement 1;\nstatement 2;\nGO\n\nstatement 3; statement 4;" | ["statement 1", "statement 2", "statement 3", "statement 4"]
Expand Down

0 comments on commit e3f2d2c

Please sign in to comment.