mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improved sql parser.
This commit is contained in:
@@ -16,8 +16,12 @@
|
||||
package com.alibaba.druid.sql.dialect.postgresql.ast.expr;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLObject;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.visitor.PGASTVisitor;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class PGBoxExpr extends PGExprImpl {
|
||||
|
||||
private SQLExpr value;
|
||||
@@ -46,6 +50,10 @@ public class PGBoxExpr extends PGExprImpl {
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
public List<SQLObject> getChildren() {
|
||||
return Collections.<SQLObject>singletonList(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
|
||||
@@ -16,8 +16,12 @@
|
||||
package com.alibaba.druid.sql.dialect.postgresql.ast.expr;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLObject;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.visitor.PGASTVisitor;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class PGCidrExpr extends PGExprImpl {
|
||||
|
||||
private SQLExpr value;
|
||||
@@ -46,6 +50,10 @@ public class PGCidrExpr extends PGExprImpl {
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
public List<SQLObject> getChildren() {
|
||||
return Collections.<SQLObject>singletonList(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
|
||||
@@ -16,8 +16,12 @@
|
||||
package com.alibaba.druid.sql.dialect.postgresql.ast.expr;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLObject;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.visitor.PGASTVisitor;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class PGCircleExpr extends PGExprImpl {
|
||||
|
||||
private SQLExpr value;
|
||||
@@ -46,6 +50,11 @@ public class PGCircleExpr extends PGExprImpl {
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SQLObject> getChildren() {
|
||||
return Collections.<SQLObject>singletonList(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
|
||||
@@ -16,8 +16,12 @@
|
||||
package com.alibaba.druid.sql.dialect.postgresql.ast.expr;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLObject;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.visitor.PGASTVisitor;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class PGExtractExpr extends PGExprImpl {
|
||||
|
||||
private PGDateField field;
|
||||
@@ -59,6 +63,10 @@ public class PGExtractExpr extends PGExprImpl {
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
public List<SQLObject> getChildren() {
|
||||
return Collections.<SQLObject>singletonList(source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
|
||||
@@ -16,8 +16,12 @@
|
||||
package com.alibaba.druid.sql.dialect.postgresql.ast.expr;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLObject;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.visitor.PGASTVisitor;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class PGInetExpr extends PGExprImpl {
|
||||
|
||||
private SQLExpr value;
|
||||
@@ -46,6 +50,10 @@ public class PGInetExpr extends PGExprImpl {
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
public List<SQLObject> getChildren() {
|
||||
return Collections.<SQLObject>singletonList(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
|
||||
@@ -1,76 +0,0 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.sql.dialect.postgresql.ast.expr;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLExprImpl;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLLiteralExpr;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.visitor.PGASTVisitor;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
/**
|
||||
* Created by tianzhen.wtz on 2014/12/29 0029 16:10.
|
||||
* 类说明:
|
||||
*/
|
||||
public class PGIntervalExpr extends SQLExprImpl implements SQLLiteralExpr,PGExpr{
|
||||
|
||||
private SQLExpr value;
|
||||
|
||||
|
||||
public SQLExpr getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(SQLExpr value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept0(PGASTVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
PGIntervalExpr that = (PGIntervalExpr) o;
|
||||
|
||||
if (value != null ? !value.equals(that.value) : that.value != null) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return value != null ? value.hashCode() : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
this.accept0((PGASTVisitor) visitor);
|
||||
}
|
||||
|
||||
public PGIntervalExpr clone() {
|
||||
PGIntervalExpr x = new PGIntervalExpr();
|
||||
if (value != null) {
|
||||
x.setValue(value.clone());
|
||||
}
|
||||
return x;
|
||||
}
|
||||
}
|
||||
+9
@@ -16,8 +16,12 @@
|
||||
package com.alibaba.druid.sql.dialect.postgresql.ast.expr;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLObject;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.visitor.PGASTVisitor;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class PGLineSegmentsExpr extends PGExprImpl {
|
||||
|
||||
private SQLExpr value;
|
||||
@@ -46,6 +50,11 @@ public class PGLineSegmentsExpr extends PGExprImpl {
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SQLObject> getChildren() {
|
||||
return Collections.<SQLObject>singletonList(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
|
||||
@@ -16,8 +16,12 @@
|
||||
package com.alibaba.druid.sql.dialect.postgresql.ast.expr;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLObject;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.visitor.PGASTVisitor;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class PGMacAddrExpr extends PGExprImpl {
|
||||
|
||||
@@ -47,6 +51,10 @@ public class PGMacAddrExpr extends PGExprImpl {
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
public List<SQLObject> getChildren() {
|
||||
return Collections.<SQLObject>singletonList(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
|
||||
@@ -16,8 +16,12 @@
|
||||
package com.alibaba.druid.sql.dialect.postgresql.ast.expr;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLObject;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.visitor.PGASTVisitor;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class PGPointExpr extends PGExprImpl {
|
||||
|
||||
private SQLExpr value;
|
||||
@@ -46,6 +50,10 @@ public class PGPointExpr extends PGExprImpl {
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
public List<SQLObject> getChildren() {
|
||||
return Collections.<SQLObject>singletonList(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
|
||||
@@ -16,8 +16,12 @@
|
||||
package com.alibaba.druid.sql.dialect.postgresql.ast.expr;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLObject;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.visitor.PGASTVisitor;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class PGPolygonExpr extends PGExprImpl {
|
||||
|
||||
@@ -47,6 +51,10 @@ public class PGPolygonExpr extends PGExprImpl {
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
public List<SQLObject> getChildren() {
|
||||
return Collections.<SQLObject>singletonList(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
|
||||
@@ -17,21 +17,13 @@ package com.alibaba.druid.sql.dialect.postgresql.parser;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLDataType;
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLArrayExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLBinaryExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLCharExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLTimestampExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLUnaryExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLUnaryOperator;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLVariantRefExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.*;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.expr.PGBoxExpr;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.expr.PGCidrExpr;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.expr.PGCircleExpr;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.expr.PGDateField;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.expr.PGExtractExpr;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.expr.PGInetExpr;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.expr.PGIntervalExpr;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.expr.PGLineSegmentsExpr;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.expr.PGMacAddrExpr;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.expr.PGPointExpr;
|
||||
@@ -125,7 +117,7 @@ public class PGExprParser extends SQLExprParser {
|
||||
@Override
|
||||
protected SQLExpr parseInterval() {
|
||||
accept(Token.INTERVAL);
|
||||
PGIntervalExpr intervalExpr=new PGIntervalExpr();
|
||||
SQLIntervalExpr intervalExpr = new SQLIntervalExpr();
|
||||
if (lexer.token() != Token.LITERAL_CHARS) {
|
||||
return new SQLIdentifierExpr("INTERVAL");
|
||||
}
|
||||
|
||||
@@ -101,10 +101,6 @@ public interface PGASTVisitor extends SQLASTVisitor {
|
||||
|
||||
boolean visit(PGLineSegmentsExpr x);
|
||||
|
||||
void endVisit(PGIntervalExpr x);
|
||||
|
||||
boolean visit(PGIntervalExpr x);
|
||||
|
||||
void endVisit(PGShowStatement x);
|
||||
|
||||
boolean visit(PGShowStatement x);
|
||||
|
||||
-11
@@ -20,7 +20,6 @@ import com.alibaba.druid.sql.dialect.postgresql.ast.expr.PGCidrExpr;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.expr.PGCircleExpr;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.expr.PGExtractExpr;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.expr.PGInetExpr;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.expr.PGIntervalExpr;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.expr.PGLineSegmentsExpr;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.expr.PGMacAddrExpr;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.expr.PGPointExpr;
|
||||
@@ -238,16 +237,6 @@ public class PGASTVisitorAdapter extends SQLASTVisitorAdapter implements PGASTVi
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(PGIntervalExpr x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(PGIntervalExpr x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(PGShowStatement x) {
|
||||
|
||||
|
||||
+104
-14
@@ -23,13 +23,11 @@ import com.alibaba.druid.sql.ast.expr.*;
|
||||
import com.alibaba.druid.sql.ast.statement.*;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.expr.*;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.*;
|
||||
import com.alibaba.druid.sql.dialect.oracle.visitor.OracleOutputVisitor;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.expr.PGBoxExpr;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.expr.PGCidrExpr;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.expr.PGCircleExpr;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.expr.PGExtractExpr;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.expr.PGInetExpr;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.expr.PGIntervalExpr;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.expr.PGLineSegmentsExpr;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.expr.PGMacAddrExpr;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.expr.PGPointExpr;
|
||||
@@ -551,18 +549,6 @@ public class PGOutputVisitor extends SQLASTOutputVisitor implements PGASTVisitor
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(PGIntervalExpr x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(PGIntervalExpr x) {
|
||||
print0(ucase ? "INTERVAL " : "interval ");
|
||||
x.getValue().accept(this);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(PGLineSegmentsExpr x) {
|
||||
|
||||
@@ -873,4 +859,108 @@ public class PGOutputVisitor extends SQLASTOutputVisitor implements PGASTVisitor
|
||||
visit((SQLUnique) x);
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean visit(OracleSelectSubqueryTableSource x) {
|
||||
print('(');
|
||||
this.indentCount++;
|
||||
println();
|
||||
x.getSelect().accept(this);
|
||||
this.indentCount--;
|
||||
println();
|
||||
print(')');
|
||||
|
||||
if (x.getPivot() != null) {
|
||||
println();
|
||||
x.getPivot().accept(this);
|
||||
}
|
||||
|
||||
printFlashback(x.getFlashback());
|
||||
|
||||
if ((x.getAlias() != null) && (x.getAlias().length() != 0)) {
|
||||
print(' ');
|
||||
print0(x.getAlias());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean visit(OracleSelectJoin x) {
|
||||
x.getLeft().accept(this);
|
||||
SQLTableSource right = x.getRight();
|
||||
|
||||
if (x.getJoinType() == SQLJoinTableSource.JoinType.COMMA) {
|
||||
print0(", ");
|
||||
x.getRight().accept(this);
|
||||
} else {
|
||||
boolean isRoot = x.getParent() instanceof SQLSelectQueryBlock;
|
||||
if (isRoot) {
|
||||
this.indentCount++;
|
||||
}
|
||||
|
||||
println();
|
||||
print0(ucase ? x.getJoinType().name : x.getJoinType().name_lcase);
|
||||
print(' ');
|
||||
|
||||
if (right instanceof SQLJoinTableSource) {
|
||||
print('(');
|
||||
right.accept(this);
|
||||
print(')');
|
||||
} else {
|
||||
right.accept(this);
|
||||
}
|
||||
|
||||
if (isRoot) {
|
||||
this.indentCount--;
|
||||
}
|
||||
|
||||
if (x.getCondition() != null) {
|
||||
print0(ucase ? " ON " : " on ");
|
||||
x.getCondition().accept(this);
|
||||
print(' ');
|
||||
}
|
||||
|
||||
if (x.getUsing().size() > 0) {
|
||||
print0(ucase ? " USING (" : " using (");
|
||||
printAndAccept(x.getUsing(), ", ");
|
||||
print(')');
|
||||
}
|
||||
|
||||
printFlashback(x.getFlashback());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean visit(OracleDbLinkExpr x) {
|
||||
SQLExpr expr = x.getExpr();
|
||||
if (expr != null) {
|
||||
expr.accept(this);
|
||||
print('@');
|
||||
}
|
||||
print0(x.getDbLink());
|
||||
return false;
|
||||
}
|
||||
|
||||
public void endVisit(OracleDbLinkExpr x) {
|
||||
|
||||
}
|
||||
|
||||
public boolean visit(OracleDeleteStatement x) {
|
||||
return visit((SQLDeleteStatement) x);
|
||||
}
|
||||
|
||||
private void printFlashback(SQLExpr flashback) {
|
||||
if (flashback == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
println();
|
||||
|
||||
if (flashback instanceof SQLBetweenExpr) {
|
||||
flashback.accept(this);
|
||||
} else {
|
||||
print0(ucase ? "AS OF " : "as of ");
|
||||
flashback.accept(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
-12
@@ -18,7 +18,6 @@ package com.alibaba.druid.sql.dialect.postgresql.visitor;
|
||||
import java.util.Map;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLName;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelectStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLTableSource;
|
||||
@@ -27,7 +26,6 @@ import com.alibaba.druid.sql.dialect.postgresql.ast.expr.PGCidrExpr;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.expr.PGCircleExpr;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.expr.PGExtractExpr;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.expr.PGInetExpr;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.expr.PGIntervalExpr;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.expr.PGLineSegmentsExpr;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.expr.PGMacAddrExpr;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.expr.PGPointExpr;
|
||||
@@ -311,16 +309,6 @@ public class PGSchemaStatVisitor extends SchemaStatVisitor implements PGASTVisit
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(PGIntervalExpr x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(PGIntervalExpr x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(PGLineSegmentsExpr x) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user