Skip to content

Commit

Permalink
added support for T-SQL left and right joins (*= and =*)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nico authored and Nico committed Jan 29, 2019
1 parent 7cd189c commit 786c8fc
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
import net.sf.jsqlparser.expression.operators.relational.NotEqualsTo;
import net.sf.jsqlparser.expression.operators.relational.RegExpMatchOperator;
import net.sf.jsqlparser.expression.operators.relational.RegExpMySQLOperator;
import net.sf.jsqlparser.expression.operators.relational.TSQLLeftJoin;
import net.sf.jsqlparser.expression.operators.relational.TSQLRightJoin;
import net.sf.jsqlparser.expression.operators.relational.JsonOperator;
import net.sf.jsqlparser.schema.Column;
import net.sf.jsqlparser.statement.select.SubSelect;
Expand Down Expand Up @@ -180,4 +182,8 @@ public interface ExpressionVisitor {

public void visit(NotExpression aThis);

public void visit(TSQLLeftJoin tsqlLeftJoin);

public void visit(TSQLRightJoin tsqlRightJoin);

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import net.sf.jsqlparser.expression.operators.arithmetic.*;
import net.sf.jsqlparser.expression.operators.conditional.AndExpression;
import net.sf.jsqlparser.expression.operators.conditional.OrExpression;
import net.sf.jsqlparser.expression.operators.relational.JsonOperator;
import net.sf.jsqlparser.expression.operators.relational.*;
import net.sf.jsqlparser.schema.Column;
import net.sf.jsqlparser.statement.select.AllColumns;
Expand Down Expand Up @@ -508,4 +507,14 @@ public void visit(DateTimeLiteralExpression literal) {

}

@Override
public void visit(TSQLLeftJoin tsqlLeftJoin) {
visitBinaryExpression(tsqlLeftJoin);
}

@Override
public void visit(TSQLRightJoin tsqlRightJoin) {
visitBinaryExpression(tsqlRightJoin);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2013 JSQLParser
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
package net.sf.jsqlparser.expression.operators.relational;

import net.sf.jsqlparser.expression.ExpressionVisitor;

public class TSQLLeftJoin extends ComparisonOperator {

public TSQLLeftJoin() {
super("*=");
}

@Override
public void accept(ExpressionVisitor expressionVisitor) {
expressionVisitor.visit(this);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2013 JSQLParser
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
package net.sf.jsqlparser.expression.operators.relational;

import net.sf.jsqlparser.expression.ExpressionVisitor;

public class TSQLRightJoin extends ComparisonOperator {

public TSQLRightJoin() {
super("=*");
}

@Override
public void accept(ExpressionVisitor expressionVisitor) {
expressionVisitor.visit(this);
}
}
12 changes: 12 additions & 0 deletions src/main/java/net/sf/jsqlparser/util/TablesNamesFinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@
import net.sf.jsqlparser.expression.operators.relational.NotEqualsTo;
import net.sf.jsqlparser.expression.operators.relational.RegExpMatchOperator;
import net.sf.jsqlparser.expression.operators.relational.RegExpMySQLOperator;
import net.sf.jsqlparser.expression.operators.relational.TSQLLeftJoin;
import net.sf.jsqlparser.expression.operators.relational.TSQLRightJoin;
import net.sf.jsqlparser.schema.Column;
import net.sf.jsqlparser.schema.Table;
import net.sf.jsqlparser.statement.Block;
Expand Down Expand Up @@ -859,4 +861,14 @@ public void visit(DescribeStatement describe) {
public void visit(ExplainStatement explain) {
explain.getStatement().accept(this);
}

@Override
public void visit(TSQLLeftJoin tsqlLeftJoin) {
visitBinaryExpression(tsqlLeftJoin);
}

@Override
public void visit(TSQLRightJoin tsqlRightJoin) {
visitBinaryExpression(tsqlRightJoin);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@
import net.sf.jsqlparser.expression.operators.relational.RegExpMatchOperator;
import net.sf.jsqlparser.expression.operators.relational.RegExpMySQLOperator;
import net.sf.jsqlparser.expression.operators.relational.SupportsOldOracleJoinSyntax;
import net.sf.jsqlparser.expression.operators.relational.TSQLLeftJoin;
import net.sf.jsqlparser.expression.operators.relational.TSQLRightJoin;
import net.sf.jsqlparser.schema.Column;
import net.sf.jsqlparser.schema.Table;
import net.sf.jsqlparser.statement.select.OrderByElement;
Expand Down Expand Up @@ -812,4 +814,14 @@ public void visit(DateTimeLiteralExpression literal) {
buffer.append(literal.toString());
}

@Override
public void visit(TSQLLeftJoin tsqlLeftJoin) {
visitBinaryExpression(tsqlLeftJoin, " *= ");
}

@Override
public void visit(TSQLRightJoin tsqlRightJoin) {
visitBinaryExpression(tsqlRightJoin, " =* ");
}

}
2 changes: 2 additions & 0 deletions src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt
Original file line number Diff line number Diff line change
Expand Up @@ -2182,6 +2182,8 @@ Expression RegularCondition() #RegularCondition:
">" { result = new GreaterThan(); }
| "<" { result = new MinorThan(); }
| "=" { result = new EqualsTo(); }
| "*=" { result = new TSQLLeftJoin(); }
| "=*" { result = new TSQLRightJoin(); }
| token=<OP_GREATERTHANEQUALS> { result = new GreaterThanEquals(token.image); }
| token=<OP_MINORTHANEQUALS> { result = new MinorThanEquals(token.image); }
| token=<OP_NOTEQUALSSTANDARD> { result = new NotEqualsTo(token.image); }
Expand Down
14 changes: 13 additions & 1 deletion src/test/java/net/sf/jsqlparser/statement/select/SelectTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1810,12 +1810,24 @@ public void testFunctionRight() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed(statement);
}

@Test
public void testTSQLJoin() throws JSQLParserException {
String stmt = "SELECT * FROM tabelle1, tabelle2 WHERE tabelle1.a *= tabelle2.b";
assertSqlCanBeParsedAndDeparsed(stmt);
}

@Test
public void testTSQLJoin2() throws JSQLParserException {
String stmt = "SELECT * FROM tabelle1, tabelle2 WHERE tabelle1.a =* tabelle2.b";
assertSqlCanBeParsedAndDeparsed(stmt);
}

@Test
public void testOracleJoin() throws JSQLParserException {
String stmt = "SELECT * FROM tabelle1, tabelle2 WHERE tabelle1.a = tabelle2.b(+)";
assertSqlCanBeParsedAndDeparsed(stmt);
}

@Test
public void testOracleJoin2() throws JSQLParserException {
String stmt = "SELECT * FROM tabelle1, tabelle2 WHERE tabelle1.a(+) = tabelle2.b";
Expand Down

0 comments on commit 786c8fc

Please sign in to comment.