-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathStatementSeparatorTest.java
More file actions
79 lines (69 loc) · 2.89 KB
/
StatementSeparatorTest.java
File metadata and controls
79 lines (69 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2023 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.statement;
import net.sf.jsqlparser.JSQLParserException;
import net.sf.jsqlparser.parser.CCJSqlParserUtil;
import net.sf.jsqlparser.test.TestUtils;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class StatementSeparatorTest {
@Test
void testDoubleNewLine() throws JSQLParserException {
String sqlStr =
"SELECT * FROM DUAL\n\n\nSELECT * FROM DUAL\n\n\n\nSELECT * FROM dual\n\n\n\n\nSELECT * FROM dual";
Statements statements = CCJSqlParserUtil.parseStatements(sqlStr);
Assertions.assertEquals(4, statements.size());
}
@Test
void testNewLineSlash() throws JSQLParserException {
String sqlStr =
"SELECT * FROM DUAL\n\n\nSELECT * FROM DUAL\n/\nSELECT * FROM dual\n/\n\nSELECT * FROM dual";
Statements statements = CCJSqlParserUtil.parseStatements(sqlStr);
Assertions.assertEquals(4, statements.size());
}
@Test
void testNewLineGo() throws JSQLParserException {
String sqlStr =
"SELECT * FROM DUAL\n\n\nSELECT * FROM DUAL\nGO\nSELECT * FROM dual\ngo\n\nSELECT * FROM dual\ngo";
Statements statements = CCJSqlParserUtil.parseStatements(sqlStr);
Assertions.assertEquals(4, statements.size());
}
@Test
void testNewLineNotGoIssue() throws JSQLParserException {
String sqlStr =
"select name,\ngoods from test_table";
Statements statements = CCJSqlParserUtil.parseStatements(sqlStr);
Assertions.assertEquals(1, statements.size());
}
@Test
void testOracleBlock() throws JSQLParserException {
String sqlStr = "BEGIN\n" + "\n" + "SELECT * FROM TABLE;\n" + "\n" + "END\n" + "/\n";
Statement statement = TestUtils.assertSqlCanBeParsedAndDeparsed(sqlStr, true);
}
@Test
void testMSSQLBlock() throws JSQLParserException {
String sqlStr = "create view MyView1 as\n" + "select Id,Name from table1\n" + "go\n"
+ "create view MyView2 as\n" + "select Id,Name from table1\n" + "go";
Statements statements = CCJSqlParserUtil.parseStatements(sqlStr);
Assertions.assertEquals(2, statements.size());
}
@Test
void testSOQLIncludes() throws JSQLParserException {
String sqlStr =
"select name,\ngoods from test_table where option includes ('option1', 'option2')";
Statement statement = TestUtils.assertSqlCanBeParsedAndDeparsed(sqlStr, true);
}
@Test
void testSOQLExcludes() throws JSQLParserException {
String sqlStr =
"select name,\ngoods from test_table where option excludes ('option1', 'option2')";
Statement statement = TestUtils.assertSqlCanBeParsedAndDeparsed(sqlStr, true);
}
}