Skip to content
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

Improved handling of endDelimiter="/" #3118

Merged
merged 3 commits into from Aug 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -159,7 +159,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 @@ -15,7 +15,7 @@ class StringUtilTest extends Specification {
that Arrays.asList(StringUtil.processMultiLineSQL(rawString, stripComments, splitStatements, endDelimiter)), Matchers.contains(expected.toArray())

where:
stripComments | splitStatements | endDelimiter | rawString | expected
stripComments | splitStatements | endDelimiter | rawString | expected
true | true | null | "/**\nSome comments go here\n**/\ncreate table sqlfilerollback (id int);\n\n/**\nSome morecomments go here\n**/\ncreate table sqlfilerollback2 (id int);" | ["create table sqlfilerollback (id int)", "create table sqlfilerollback2 (id int)"]
true | true | null | "/*\nThis is a test comment of MS-SQL script\n*/\n\nSelect * from Test;\nUpdate Test set field = 1" | ["Select * from Test", "Update Test set field = 1"]
true | true | null | "some sql/*Some text\nmore text*/more sql" | ["some sqlmore sql"]
Expand All @@ -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