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:
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.alibaba.druid.sql.ast;
|
||||
|
||||
import com.alibaba.druid.sql.ast.expr.SQLIntegerExpr;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -37,6 +38,17 @@ public class SQLDataTypeImpl extends SQLObjectImpl implements SQLDataType {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public SQLDataTypeImpl(String name, int precision) {
|
||||
this(name);
|
||||
addArgument(new SQLIntegerExpr(precision));
|
||||
}
|
||||
|
||||
public SQLDataTypeImpl(String name, int precision, int scale) {
|
||||
this(name);
|
||||
addArgument(new SQLIntegerExpr(precision));
|
||||
addArgument(new SQLIntegerExpr(scale));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
|
||||
@@ -21,7 +21,7 @@ import java.util.List;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLTableElement;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class SQLDeclareItem extends SQLObjectImpl {
|
||||
public class SQLDeclareItem extends SQLObjectImpl implements SQLObjectWithDataType {
|
||||
|
||||
protected Type type;
|
||||
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
public interface SQLObjectWithDataType extends SQLObject {
|
||||
SQLDataType getDataType();
|
||||
void setDataType(SQLDataType dataType);
|
||||
}
|
||||
@@ -20,7 +20,7 @@ import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SQLParameter extends SQLObjectImpl {
|
||||
public class SQLParameter extends SQLObjectImpl implements SQLObjectWithDataType {
|
||||
|
||||
private SQLExpr name;
|
||||
private SQLDataType dataType;
|
||||
@@ -59,6 +59,9 @@ public class SQLParameter extends SQLObjectImpl {
|
||||
}
|
||||
|
||||
public void setDataType(SQLDataType dataType) {
|
||||
if (dataType != null) {
|
||||
dataType.setParent(this);
|
||||
}
|
||||
this.dataType = dataType;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,9 +18,10 @@ package com.alibaba.druid.sql.ast.expr;
|
||||
import com.alibaba.druid.sql.ast.SQLDataType;
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLExprImpl;
|
||||
import com.alibaba.druid.sql.ast.SQLObjectWithDataType;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class SQLCastExpr extends SQLExprImpl {
|
||||
public class SQLCastExpr extends SQLExprImpl implements SQLObjectWithDataType {
|
||||
|
||||
protected SQLExpr expr;
|
||||
protected SQLDataType dataType;
|
||||
@@ -45,6 +46,9 @@ public class SQLCastExpr extends SQLExprImpl {
|
||||
}
|
||||
|
||||
public void setDataType(SQLDataType dataType) {
|
||||
if (dataType != null) {
|
||||
dataType.setParent(this);
|
||||
}
|
||||
this.dataType = dataType;
|
||||
}
|
||||
|
||||
|
||||
@@ -41,6 +41,10 @@ public class SQLCharacterDataType extends SQLDataTypeImpl {
|
||||
super(name);
|
||||
}
|
||||
|
||||
public SQLCharacterDataType(String name, int precision){
|
||||
super(name, precision);
|
||||
}
|
||||
|
||||
public String getCharSetName() {
|
||||
return charSetName;
|
||||
}
|
||||
|
||||
@@ -19,16 +19,13 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLDataType;
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLName;
|
||||
import com.alibaba.druid.sql.ast.SQLObjectImpl;
|
||||
import com.alibaba.druid.sql.ast.*;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLPropertyExpr;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
public class SQLColumnDefinition extends SQLObjectImpl implements SQLTableElement {
|
||||
public class SQLColumnDefinition extends SQLObjectImpl implements SQLTableElement, SQLObjectWithDataType {
|
||||
protected String dbType;
|
||||
|
||||
protected SQLName name;
|
||||
|
||||
@@ -25,7 +25,7 @@ import java.util.List;
|
||||
/**
|
||||
* Created by wenshao on 23/05/2017.
|
||||
*/
|
||||
public class SQLCreateFunctionStatement extends SQLStatementImpl implements SQLCreateStatement {
|
||||
public class SQLCreateFunctionStatement extends SQLStatementImpl implements SQLCreateStatement, SQLObjectWithDataType {
|
||||
private SQLName definer;
|
||||
|
||||
private boolean create = true;
|
||||
@@ -85,6 +85,7 @@ public class SQLCreateFunctionStatement extends SQLStatementImpl implements SQLC
|
||||
acceptChild(visitor, definer);
|
||||
acceptChild(visitor, name);
|
||||
acceptChild(visitor, parameters);
|
||||
acceptChild(visitor, returnDataType);
|
||||
acceptChild(visitor, block);
|
||||
}
|
||||
visitor.endVisit(this);
|
||||
@@ -199,4 +200,14 @@ public class SQLCreateFunctionStatement extends SQLStatementImpl implements SQLC
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SQLDataType getDataType() {
|
||||
return returnDataType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDataType(SQLDataType dataType) {
|
||||
this.setReturnDataType(dataType);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user