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:
@@ -17,4 +17,8 @@ package com.alibaba.druid.sql.ast;
|
||||
|
||||
public interface SQLStatement extends SQLObject {
|
||||
String getDbType();
|
||||
|
||||
boolean isAfterSemi();
|
||||
|
||||
void setAfterSemi(boolean afterSemi);
|
||||
}
|
||||
|
||||
@@ -22,6 +22,8 @@ public abstract class SQLStatementImpl extends SQLObjectImpl implements SQLState
|
||||
|
||||
private String dbType;
|
||||
|
||||
private boolean afterSemi;
|
||||
|
||||
public SQLStatementImpl(){
|
||||
|
||||
}
|
||||
@@ -46,4 +48,12 @@ public abstract class SQLStatementImpl extends SQLObjectImpl implements SQLState
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
throw new UnsupportedOperationException(this.getClass().getName());
|
||||
}
|
||||
|
||||
public boolean isAfterSemi() {
|
||||
return afterSemi;
|
||||
}
|
||||
|
||||
public void setAfterSemi(boolean afterSemi) {
|
||||
this.afterSemi = afterSemi;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,8 @@ import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
public class SQLBlockStatement extends SQLStatementImpl {
|
||||
private String labelName;
|
||||
|
||||
private String endLabel;
|
||||
|
||||
private List<SQLParameter> parameters = new ArrayList<SQLParameter>();
|
||||
|
||||
private List<SQLStatement> statementList = new ArrayList<SQLStatement>();
|
||||
@@ -73,4 +75,12 @@ public class SQLBlockStatement extends SQLStatementImpl {
|
||||
public void setException(SQLStatement exception) {
|
||||
this.exception = exception;
|
||||
}
|
||||
|
||||
public String getEndLabel() {
|
||||
return endLabel;
|
||||
}
|
||||
|
||||
public void setEndLabel(String endLabel) {
|
||||
this.endLabel = endLabel;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.ast.SQLStatementImpl;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class SQLCommentStatement extends SQLStatementImpl implements SQLStatement {
|
||||
public class SQLCommentStatement extends SQLStatementImpl {
|
||||
|
||||
public static enum Type {
|
||||
TABLE, COLUMN
|
||||
|
||||
@@ -1,3 +1,18 @@
|
||||
/*
|
||||
* 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.ast.statement;
|
||||
|
||||
import com.alibaba.druid.sql.ast.*;
|
||||
|
||||
@@ -72,6 +72,9 @@ public class SQLIfStatement extends SQLStatementImpl {
|
||||
}
|
||||
|
||||
public void setElseItem(Else elseItem) {
|
||||
if (elseItem != null) {
|
||||
elseItem.setParent(this);
|
||||
}
|
||||
this.elseItem = elseItem;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,8 @@ public class SQLInsertStatement extends SQLInsertInto implements SQLStatement {
|
||||
|
||||
protected boolean upsert = false; // for phoenix
|
||||
|
||||
private boolean afterSemi;
|
||||
|
||||
public SQLInsertStatement(){
|
||||
|
||||
}
|
||||
@@ -105,4 +107,14 @@ public class SQLInsertStatement extends SQLInsertInto implements SQLStatement {
|
||||
public void setDbType(String dbType) {
|
||||
this.dbType = dbType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAfterSemi() {
|
||||
return afterSemi;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAfterSemi(boolean afterSemi) {
|
||||
this.afterSemi = afterSemi;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* 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.ast.statement;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLStatementImpl;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class SQLReturnStatement extends SQLStatementImpl {
|
||||
|
||||
private SQLExpr expr;
|
||||
|
||||
public SQLReturnStatement() {
|
||||
|
||||
}
|
||||
|
||||
public SQLReturnStatement(String dbType) {
|
||||
super (dbType);
|
||||
}
|
||||
|
||||
public SQLExpr getExpr() {
|
||||
return expr;
|
||||
}
|
||||
|
||||
public void setExpr(SQLExpr expr) {
|
||||
if (expr != null) {
|
||||
expr.setParent(this);
|
||||
}
|
||||
this.expr = expr;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
acceptChild(visitor, expr);
|
||||
}
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,7 @@ import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.ast.SQLStatementImpl;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class SQLUseStatement extends SQLStatementImpl implements SQLStatement {
|
||||
public class SQLUseStatement extends SQLStatementImpl {
|
||||
|
||||
private SQLName database;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user