Skip to content

Commit 14637ce

Browse files
fix: GO shall terminate statement only, when appearing alone on an empty line
- fixes #1929
1 parent e2cb134 commit 14637ce

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ TOKEN: /* SQL Keywords. prefixed with K_ to avoid name clashes */
486486

487487
TOKEN : /* Statement Separators */
488488
{
489-
<ST_SEMICOLON : ( ";" | ("\n\n\n") | "\n/\n" | "\ngo" ) >
489+
<ST_SEMICOLON : ( ";" | ("\n\n\n") | "\n/\n" | "\ngo\n" ) >
490490
}
491491

492492
TOKEN : /* Operators */

src/test/java/net/sf/jsqlparser/statement/StatementSeparatorTest.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,31 @@ void testDoubleNewLine() throws JSQLParserException {
2121
String sqlStr =
2222
"SELECT * FROM DUAL\n\n\nSELECT * FROM DUAL\n\n\n\nSELECT * FROM dual\n\n\n\n\nSELECT * FROM dual";
2323
Statements statements = CCJSqlParserUtil.parseStatements(sqlStr);
24-
Assertions.assertEquals(4, statements.getStatements().size());
24+
Assertions.assertEquals(4, statements.size());
2525
}
2626

2727
@Test
2828
void testNewLineSlash() throws JSQLParserException {
2929
String sqlStr =
3030
"SELECT * FROM DUAL\n\n\nSELECT * FROM DUAL\n/\nSELECT * FROM dual\n/\n\nSELECT * FROM dual";
3131
Statements statements = CCJSqlParserUtil.parseStatements(sqlStr);
32-
Assertions.assertEquals(4, statements.getStatements().size());
32+
Assertions.assertEquals(4, statements.size());
3333
}
3434

3535
@Test
3636
void testNewLineGo() throws JSQLParserException {
3737
String sqlStr =
3838
"SELECT * FROM DUAL\n\n\nSELECT * FROM DUAL\nGO\nSELECT * FROM dual\ngo\n\nSELECT * FROM dual\ngo";
3939
Statements statements = CCJSqlParserUtil.parseStatements(sqlStr);
40-
Assertions.assertEquals(4, statements.getStatements().size());
40+
Assertions.assertEquals(4, statements.size());
41+
}
42+
43+
@Test
44+
void testNewLineNotGoIssue() throws JSQLParserException {
45+
String sqlStr =
46+
"select name,\ngoods from test_table";
47+
Statements statements = CCJSqlParserUtil.parseStatements(sqlStr);
48+
Assertions.assertEquals(1, statements.size());
4149
}
4250

4351
@Test
@@ -52,6 +60,6 @@ void testMSSQLBlock() throws JSQLParserException {
5260
String sqlStr = "create view MyView1 as\n" + "select Id,Name from table1\n" + "go\n"
5361
+ "create view MyView2 as\n" + "select Id,Name from table1\n" + "go";
5462
Statements statements = CCJSqlParserUtil.parseStatements(sqlStr);
55-
Assertions.assertEquals(2, statements.getStatements().size());
63+
Assertions.assertEquals(2, statements.size());
5664
}
5765
}

0 commit comments

Comments
 (0)