Skip to content

Commit 786c8fc

Browse files
NicoNico
authored andcommitted
added support for T-SQL left and right joins (*= and =*)
1 parent 7cd189c commit 786c8fc

File tree

8 files changed

+127
-2
lines changed

8 files changed

+127
-2
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
import net.sf.jsqlparser.expression.operators.relational.NotEqualsTo;
4949
import net.sf.jsqlparser.expression.operators.relational.RegExpMatchOperator;
5050
import net.sf.jsqlparser.expression.operators.relational.RegExpMySQLOperator;
51+
import net.sf.jsqlparser.expression.operators.relational.TSQLLeftJoin;
52+
import net.sf.jsqlparser.expression.operators.relational.TSQLRightJoin;
5153
import net.sf.jsqlparser.expression.operators.relational.JsonOperator;
5254
import net.sf.jsqlparser.schema.Column;
5355
import net.sf.jsqlparser.statement.select.SubSelect;
@@ -180,4 +182,8 @@ public interface ExpressionVisitor {
180182

181183
public void visit(NotExpression aThis);
182184

185+
public void visit(TSQLLeftJoin tsqlLeftJoin);
186+
187+
public void visit(TSQLRightJoin tsqlRightJoin);
188+
183189
}

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import net.sf.jsqlparser.expression.operators.arithmetic.*;
2525
import net.sf.jsqlparser.expression.operators.conditional.AndExpression;
2626
import net.sf.jsqlparser.expression.operators.conditional.OrExpression;
27-
import net.sf.jsqlparser.expression.operators.relational.JsonOperator;
2827
import net.sf.jsqlparser.expression.operators.relational.*;
2928
import net.sf.jsqlparser.schema.Column;
3029
import net.sf.jsqlparser.statement.select.AllColumns;
@@ -508,4 +507,14 @@ public void visit(DateTimeLiteralExpression literal) {
508507

509508
}
510509

510+
@Override
511+
public void visit(TSQLLeftJoin tsqlLeftJoin) {
512+
visitBinaryExpression(tsqlLeftJoin);
513+
}
514+
515+
@Override
516+
public void visit(TSQLRightJoin tsqlRightJoin) {
517+
visitBinaryExpression(tsqlRightJoin);
518+
}
519+
511520
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* #%L
3+
* JSQLParser library
4+
* %%
5+
* Copyright (C) 2004 - 2013 JSQLParser
6+
* %%
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU Lesser General Public License as
9+
* published by the Free Software Foundation, either version 2.1 of the
10+
* License, or (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Lesser Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Lesser Public
18+
* License along with this program. If not, see
19+
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
20+
* #L%
21+
*/
22+
package net.sf.jsqlparser.expression.operators.relational;
23+
24+
import net.sf.jsqlparser.expression.ExpressionVisitor;
25+
26+
public class TSQLLeftJoin extends ComparisonOperator {
27+
28+
public TSQLLeftJoin() {
29+
super("*=");
30+
}
31+
32+
@Override
33+
public void accept(ExpressionVisitor expressionVisitor) {
34+
expressionVisitor.visit(this);
35+
}
36+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* #%L
3+
* JSQLParser library
4+
* %%
5+
* Copyright (C) 2004 - 2013 JSQLParser
6+
* %%
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU Lesser General Public License as
9+
* published by the Free Software Foundation, either version 2.1 of the
10+
* License, or (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Lesser Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Lesser Public
18+
* License along with this program. If not, see
19+
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
20+
* #L%
21+
*/
22+
package net.sf.jsqlparser.expression.operators.relational;
23+
24+
import net.sf.jsqlparser.expression.ExpressionVisitor;
25+
26+
public class TSQLRightJoin extends ComparisonOperator {
27+
28+
public TSQLRightJoin() {
29+
super("=*");
30+
}
31+
32+
@Override
33+
public void accept(ExpressionVisitor expressionVisitor) {
34+
expressionVisitor.visit(this);
35+
}
36+
}

src/main/java/net/sf/jsqlparser/util/TablesNamesFinder.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@
9191
import net.sf.jsqlparser.expression.operators.relational.NotEqualsTo;
9292
import net.sf.jsqlparser.expression.operators.relational.RegExpMatchOperator;
9393
import net.sf.jsqlparser.expression.operators.relational.RegExpMySQLOperator;
94+
import net.sf.jsqlparser.expression.operators.relational.TSQLLeftJoin;
95+
import net.sf.jsqlparser.expression.operators.relational.TSQLRightJoin;
9496
import net.sf.jsqlparser.schema.Column;
9597
import net.sf.jsqlparser.schema.Table;
9698
import net.sf.jsqlparser.statement.Block;
@@ -859,4 +861,14 @@ public void visit(DescribeStatement describe) {
859861
public void visit(ExplainStatement explain) {
860862
explain.getStatement().accept(this);
861863
}
864+
865+
@Override
866+
public void visit(TSQLLeftJoin tsqlLeftJoin) {
867+
visitBinaryExpression(tsqlLeftJoin);
868+
}
869+
870+
@Override
871+
public void visit(TSQLRightJoin tsqlRightJoin) {
872+
visitBinaryExpression(tsqlRightJoin);
873+
}
862874
}

src/main/java/net/sf/jsqlparser/util/deparser/ExpressionDeParser.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@
9494
import net.sf.jsqlparser.expression.operators.relational.RegExpMatchOperator;
9595
import net.sf.jsqlparser.expression.operators.relational.RegExpMySQLOperator;
9696
import net.sf.jsqlparser.expression.operators.relational.SupportsOldOracleJoinSyntax;
97+
import net.sf.jsqlparser.expression.operators.relational.TSQLLeftJoin;
98+
import net.sf.jsqlparser.expression.operators.relational.TSQLRightJoin;
9799
import net.sf.jsqlparser.schema.Column;
98100
import net.sf.jsqlparser.schema.Table;
99101
import net.sf.jsqlparser.statement.select.OrderByElement;
@@ -812,4 +814,14 @@ public void visit(DateTimeLiteralExpression literal) {
812814
buffer.append(literal.toString());
813815
}
814816

817+
@Override
818+
public void visit(TSQLLeftJoin tsqlLeftJoin) {
819+
visitBinaryExpression(tsqlLeftJoin, " *= ");
820+
}
821+
822+
@Override
823+
public void visit(TSQLRightJoin tsqlRightJoin) {
824+
visitBinaryExpression(tsqlRightJoin, " =* ");
825+
}
826+
815827
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2182,6 +2182,8 @@ Expression RegularCondition() #RegularCondition:
21822182
">" { result = new GreaterThan(); }
21832183
| "<" { result = new MinorThan(); }
21842184
| "=" { result = new EqualsTo(); }
2185+
| "*=" { result = new TSQLLeftJoin(); }
2186+
| "=*" { result = new TSQLRightJoin(); }
21852187
| token=<OP_GREATERTHANEQUALS> { result = new GreaterThanEquals(token.image); }
21862188
| token=<OP_MINORTHANEQUALS> { result = new MinorThanEquals(token.image); }
21872189
| token=<OP_NOTEQUALSSTANDARD> { result = new NotEqualsTo(token.image); }

src/test/java/net/sf/jsqlparser/statement/select/SelectTest.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1810,12 +1810,24 @@ public void testFunctionRight() throws JSQLParserException {
18101810
assertSqlCanBeParsedAndDeparsed(statement);
18111811
}
18121812

1813+
@Test
1814+
public void testTSQLJoin() throws JSQLParserException {
1815+
String stmt = "SELECT * FROM tabelle1, tabelle2 WHERE tabelle1.a *= tabelle2.b";
1816+
assertSqlCanBeParsedAndDeparsed(stmt);
1817+
}
1818+
1819+
@Test
1820+
public void testTSQLJoin2() throws JSQLParserException {
1821+
String stmt = "SELECT * FROM tabelle1, tabelle2 WHERE tabelle1.a =* tabelle2.b";
1822+
assertSqlCanBeParsedAndDeparsed(stmt);
1823+
}
1824+
18131825
@Test
18141826
public void testOracleJoin() throws JSQLParserException {
18151827
String stmt = "SELECT * FROM tabelle1, tabelle2 WHERE tabelle1.a = tabelle2.b(+)";
18161828
assertSqlCanBeParsedAndDeparsed(stmt);
18171829
}
1818-
1830+
18191831
@Test
18201832
public void testOracleJoin2() throws JSQLParserException {
18211833
String stmt = "SELECT * FROM tabelle1, tabelle2 WHERE tabelle1.a(+) = tabelle2.b";

0 commit comments

Comments
 (0)