File tree Expand file tree Collapse file tree 3 files changed +31
-4
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
-4
lines changed Original file line number Diff line number Diff line change @@ -97,8 +97,8 @@ public void setFetch(Fetch fetch) {
97
97
this .fetch = fetch ;
98
98
}
99
99
100
- public Fetch getWithIsolation () {
101
- return fetch ;
100
+ public WithIsolation getWithIsolation () {
101
+ return this . withIsolation ;
102
102
}
103
103
104
104
public void setWithIsolation (WithIsolation withIsolation ) {
Original file line number Diff line number Diff line change @@ -1938,16 +1938,24 @@ SelectBody SetOperationList() #SetOperationList: {
1938
1938
((PlainSelect)selects.get(0)).setUseBrackets(true);
1939
1939
return selects.get(0);
1940
1940
} else {
1941
- if (selects.size()>1 && selects.get(selects.size()-1) instanceof PlainSelect) {
1941
+ if (selects.size()>1 && selects.get(selects.size()-1) instanceof PlainSelect && !brackets.get(brackets.size() - 1) ) {
1942
1942
PlainSelect ps = (PlainSelect)selects.get(selects.size()-1);
1943
- if (ps.getOrderByElements() != null && !brackets.get(brackets.size() - 1) ) {
1943
+ if (ps.getOrderByElements() != null) {
1944
1944
list.setOrderByElements(ps.getOrderByElements());
1945
1945
list.setLimit(ps.getLimit());
1946
1946
list.setOffset(ps.getOffset());
1947
1947
ps.setOrderByElements(null);
1948
1948
ps.setLimit(null);
1949
1949
ps.setOffset(null);
1950
1950
}
1951
+ if (ps.getFetch() != null) {
1952
+ list.setFetch(ps.getFetch());
1953
+ ps.setFetch(null);
1954
+ }
1955
+ if (ps.getWithIsolation() != null) {
1956
+ list.setWithIsolation(ps.getWithIsolation());
1957
+ ps.setWithIsolation(null);
1958
+ }
1951
1959
}
1952
1960
list.setBracketsOpsAndSelects(brackets,selects,operations);
1953
1961
return list;
Original file line number Diff line number Diff line change @@ -898,6 +898,25 @@ public void testUnion() throws JSQLParserException {
898
898
+ "SELECT * FROM mytable3 WHERE mytable3.col = ? UNION "
899
899
+ "SELECT * FROM mytable2 LIMIT 3, 4" ;
900
900
assertStatementCanBeDeparsedAs (select , statementToString );
901
+
902
+ //with fetch and with ur
903
+ String statement2 = "SELECT * FROM mytable WHERE mytable.col = 9 UNION "
904
+ + "SELECT * FROM mytable3 WHERE mytable3.col = ? UNION " + "SELECT * FROM mytable2 ORDER BY COL DESC FETCH FIRST 1 ROWS ONLY WITH UR" ;
905
+
906
+ Select select2 = (Select ) parserManager .parse (new StringReader (statement2 ));
907
+ SetOperationList setList2 = (SetOperationList ) select2 .getSelectBody ();
908
+ assertEquals (3 , setList2 .getSelects ().size ());
909
+ assertEquals ("mytable" , ((Table ) ((PlainSelect ) setList2 .getSelects ().get (0 )).getFromItem ()).
910
+ getName ());
911
+ assertEquals ("mytable3" , ((Table ) ((PlainSelect ) setList2 .getSelects ().get (1 )).getFromItem ()).
912
+ getName ());
913
+ assertEquals ("mytable2" , ((Table ) ((PlainSelect ) setList2 .getSelects ().get (2 )).getFromItem ()).
914
+ getName ());
915
+ assertEquals (1 , ((SetOperationList ) setList2 ).getFetch ().getRowCount ());
916
+
917
+ assertEquals ("UR" , ((SetOperationList ) setList2 ).getWithIsolation ().getIsolation ());
918
+
919
+ assertStatementCanBeDeparsedAs (select2 , statement2 );
901
920
}
902
921
903
922
@ Test
You can’t perform that action at this time.
0 commit comments