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 {
15
15
16
16
private boolean hasParenthesis = false ;
17
17
private boolean isPercentage = false ;
18
+ private boolean isWithTies = false ;
18
19
private Expression expression ;
19
20
20
21
public Expression getExpression () {
@@ -41,6 +42,14 @@ public void setPercentage(boolean percentage) {
41
42
this .isPercentage = percentage ;
42
43
}
43
44
45
+ public void setWithTies (boolean withTies ) {
46
+ this .isWithTies = withTies ;
47
+ }
48
+
49
+ public boolean isWithTies () {
50
+ return isWithTies ;
51
+ }
52
+
44
53
@ Override
45
54
public String toString () {
46
55
String result = "TOP " ;
@@ -59,6 +68,10 @@ public String toString() {
59
68
result += " PERCENT" ;
60
69
}
61
70
71
+ if (isWithTies ) {
72
+ result += " WITH TIES" ;
73
+ }
74
+
62
75
return result ;
63
76
}
64
77
Original file line number Diff line number Diff line change @@ -421,6 +421,7 @@ TOKEN: /* SQL Keywords. prefixed with K_ to avoid name clashes */
421
421
| <K_WHERE:"WHERE">
422
422
| <K_WINDOW:"WINDOW">
423
423
| <K_WITH:"WITH">
424
+ | <K_WITH_TIES:"WITH TIES">
424
425
| <K_WITHIN:"WITHIN">
425
426
| <K_WITHOUT:"WITHOUT">
426
427
| <K_WORK:"WORK">
@@ -2903,6 +2904,7 @@ Top Top():
2903
2904
{ top.setParenthesis(true);}
2904
2905
")"
2905
2906
) [ LOOKAHEAD(2) <K_PERCENT> { top.setPercentage(true); } ]
2907
+ [ LOOKAHEAD(2) <K_WITH_TIES> { top.setWithTies(true); }]
2906
2908
{
2907
2909
return top;
2908
2910
}
Original file line number Diff line number Diff line change @@ -663,6 +663,22 @@ public void testTopWithParenthesis() throws JSQLParserException {
663
663
assertStatementCanBeDeparsedAs (select , statement );
664
664
}
665
665
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
+
666
682
@ Test
667
683
public void testTopWithJdbcParameter () throws JSQLParserException {
668
684
String statement = "SELECT TOP ?1 * FROM mytable WHERE mytable.col = 9" ;
You can’t perform that action at this time.
0 commit comments