Skip to content

Commit c9c844a

Browse files
fix: Oracle Hierarchical Expression shall allow XOR (not AND only)
- fixes #2231 Signed-off-by: Andreas Reichel <[email protected]>
1 parent 9a36a48 commit c9c844a

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

src/main/java/net/sf/jsqlparser/expression/OracleHierarchicalExpression.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ public String toString() {
6565
}
6666
b.append(connectExpression.toString());
6767
if (startExpression != null) {
68-
b.append(" START WITH ").append(startExpression.toString());
68+
b.append(" START WITH ").append(startExpression);
6969
}
7070
} else {
7171
if (startExpression != null) {
72-
b.append(" START WITH ").append(startExpression.toString());
72+
b.append(" START WITH ").append(startExpression);
7373
}
7474
b.append(" CONNECT BY ");
7575
if (isNoCycle()) {

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -3865,20 +3865,20 @@ OracleHierarchicalExpression OracleHierarchicalQueryClause():
38653865
{
38663866
(
38673867
(
3868-
<K_START> <K_WITH> expr=AndExpression() {result.setStartExpression(expr);}
3869-
<K_CONNECT> <K_BY> [ <K_NOCYCLE> { result.setNoCycle(true); } ] expr=AndExpression()
3868+
<K_START> <K_WITH> expr=XorExpression() {result.setStartExpression(expr);}
3869+
<K_CONNECT> <K_BY> [ <K_NOCYCLE> { result.setNoCycle(true); } ] expr=XorExpression()
38703870
{
38713871
result.setConnectExpression(expr);
38723872
}
38733873
)
38743874
|
38753875
(
3876-
<K_CONNECT> <K_BY> [ <K_NOCYCLE> { result.setNoCycle(true); } ] expr=AndExpression()
3876+
<K_CONNECT> <K_BY> [ <K_NOCYCLE> { result.setNoCycle(true); } ] expr=XorExpression()
38773877
{
38783878
result.setConnectExpression(expr);
38793879
result.setConnectFirst(true);
38803880
}
3881-
[ LOOKAHEAD(2) <K_START> <K_WITH> expr=AndExpression() {result.setStartExpression(expr);} ]
3881+
[ LOOKAHEAD(2) <K_START> <K_WITH> expr=XorExpression() {result.setStartExpression(expr);} ]
38823882
)
38833883
)
38843884
{
@@ -6643,7 +6643,7 @@ TableFunction TableFunction():
66436643
{
66446644
[ prefix = <K_LATERAL> ]
66456645
function=Function()
6646-
[ <K_WITH> ( withClause = <K_OFFSET> | withClause = <K_ORDINALITY> ) ]
6646+
[ LOOKAHEAD(2) <K_WITH> ( withClause = <K_OFFSET> | withClause = <K_ORDINALITY> ) ]
66476647
{
66486648
return prefix!=null
66496649
? withClause!=null
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package net.sf.jsqlparser.expression;
2+
3+
import net.sf.jsqlparser.JSQLParserException;
4+
import net.sf.jsqlparser.test.TestUtils;
5+
import org.junit.jupiter.api.Test;
6+
7+
class OracleHierarchicalExpressionTest {
8+
9+
@Test
10+
void testIssue2231() throws JSQLParserException {
11+
String sqlString =
12+
"select name from product where level > 1 start with 1 = 1 or 1 = 2 connect by nextversion = prior activeversion";
13+
TestUtils.assertSqlCanBeParsedAndDeparsed(sqlString, true);
14+
}
15+
}

0 commit comments

Comments
 (0)