Skip to content

Commit

Permalink
Fix #214 recognize table name in binary expression
Browse files Browse the repository at this point in the history
  • Loading branch information
gaohongtao committed Jan 20, 2017
1 parent 6a2b5fc commit fe69b29
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ private boolean visit(final SQLExprTableSource x, final Table table) {
@Override
// TODO SELECT [别名.xxx]的情况,目前都是替换成token,解析之后应该替换回去
public final boolean visit(final SQLPropertyExpr x) {
if (!(x.getParent() instanceof SQLBinaryOpExpr) && !(x.getParent() instanceof SQLSelectItem)) {
if (null != x.getParent() && !(x.getParent() instanceof SQLBinaryOpExpr) && !(x.getParent() instanceof SQLSelectItem) && !(x.getParent() instanceof SQLBetweenExpr)) {
return super.visit(x);
}
if (!(x.getOwner() instanceof SQLIdentifierExpr)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,35 @@
</condition-context>
</condition-contexts>
</assert>

<assert id="assertSelectForInWithTableName" sql="select * from order where order.order_id in (1,2,3) and order.other_state = 'RUNNING'" expected-sql="SELECT * FROM [Token(order)] WHERE [Token(order)].order_id IN (1, 2, 3) AND [Token(order)].other_state = 'RUNNING'">
<tables>
<table name="order" />
</tables>
<condition-contexts>
<condition-context>
<condition column-name="order_id" table-name="order" operator="IN">
<value value="1" type="int" />
<value value="2" type="int" />
<value value="3" type="int" />
</condition>
</condition-context>
</condition-contexts>
</assert>

<assert id="assertSelectForBetweenWithTableName" sql="select * from order where order.order_id between 1 and 3 and order.other_state = 'RUNNING'" expected-sql="SELECT * FROM [Token(order)] WHERE [Token(order)].order_id BETWEEN 1 AND 3 AND [Token(order)].other_state = 'RUNNING'">
<tables>
<table name="order" />
</tables>
<condition-contexts>
<condition-context>
<condition column-name="order_id" table-name="order" operator="BETWEEN">
<value value="1" type="int" />
<value value="3" type="int" />
</condition>
</condition-context>
</condition-contexts>
</assert>

<assert id="assertSelectWithDateFunction" sql="select * from order where date = str_to_date('2013-01-01 01:21:01','%Y-%m-%d %H:%i:%s')" expected-sql="SELECT * FROM [Token(order)] WHERE date = str_to_date('2013-01-01 01:21:01', '%Y-%m-%d %H:%i:%s')">
<tables>
Expand Down

0 comments on commit fe69b29

Please sign in to comment.