File tree Expand file tree Collapse file tree 3 files changed +31
-0
lines changed
java/net/sf/jsqlparser/statement/select
jjtree/net/sf/jsqlparser/parser
test/java/net/sf/jsqlparser/statement/select Expand file tree Collapse file tree 3 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ public class Top {
1515
1616 private boolean hasParenthesis = false ;
1717 private boolean isPercentage = false ;
18+ private boolean isWithTies = false ;
1819 private Expression expression ;
1920
2021 public Expression getExpression () {
@@ -41,6 +42,14 @@ public void setPercentage(boolean percentage) {
4142 this .isPercentage = percentage ;
4243 }
4344
45+ public void setWithTies (boolean withTies ) {
46+ this .isWithTies = withTies ;
47+ }
48+
49+ public boolean isWithTies () {
50+ return isWithTies ;
51+ }
52+
4453 @ Override
4554 public String toString () {
4655 String result = "TOP " ;
@@ -59,6 +68,10 @@ public String toString() {
5968 result += " PERCENT" ;
6069 }
6170
71+ if (isWithTies ) {
72+ result += " WITH TIES" ;
73+ }
74+
6275 return result ;
6376 }
6477
Original file line number Diff line number Diff line change @@ -421,6 +421,7 @@ TOKEN: /* SQL Keywords. prefixed with K_ to avoid name clashes */
421421| <K_WHERE:"WHERE">
422422| <K_WINDOW:"WINDOW">
423423| <K_WITH:"WITH">
424+ | <K_WITH_TIES:"WITH TIES">
424425| <K_WITHIN:"WITHIN">
425426| <K_WITHOUT:"WITHOUT">
426427| <K_WORK:"WORK">
@@ -2903,6 +2904,7 @@ Top Top():
29032904 { top.setParenthesis(true);}
29042905 ")"
29052906 ) [ LOOKAHEAD(2) <K_PERCENT> { top.setPercentage(true); } ]
2907+ [ LOOKAHEAD(2) <K_WITH_TIES> { top.setWithTies(true); }]
29062908 {
29072909 return top;
29082910 }
Original file line number Diff line number Diff line change @@ -663,6 +663,22 @@ public void testTopWithParenthesis() throws JSQLParserException {
663663 assertStatementCanBeDeparsedAs (select , statement );
664664 }
665665
666+ @ Test
667+ public void testTopWithTies () throws JSQLParserException {
668+ final String statement = "SELECT TOP (5) PERCENT WITH TIES columnName1, columnName2 FROM tableName" ;
669+ final Select select = (Select ) parserManager .parse (new StringReader (statement ));
670+
671+ final PlainSelect selectBody = (PlainSelect ) select .getSelectBody ();
672+
673+ final Top top = selectBody .getTop ();
674+ assertEquals ("5" , top .getExpression ().toString ());
675+ assertTrue (top .hasParenthesis ());
676+ assertTrue (top .isPercentage ());
677+ assertTrue (top .isWithTies ());
678+
679+ assertStatementCanBeDeparsedAs (select , statement );
680+ }
681+
666682 @ Test
667683 public void testTopWithJdbcParameter () throws JSQLParserException {
668684 String statement = "SELECT TOP ?1 * FROM mytable WHERE mytable.col = 9" ;
You can’t perform that action at this time.
0 commit comments