mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improved mysql parser for 'create procedure statement support'
This commit is contained in:
@@ -1,93 +0,0 @@
|
||||
/*
|
||||
* Copyright 1999-2101 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.sqlserver.ast;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLDataType;
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLTableElement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.visitor.SQLServerASTVisitor;
|
||||
|
||||
public class SQLServerDeclareItem extends SQLServerObjectImpl {
|
||||
|
||||
protected Type type;
|
||||
|
||||
protected SQLExpr name;
|
||||
|
||||
protected SQLDataType dataType;
|
||||
|
||||
protected SQLExpr value;
|
||||
|
||||
protected List<SQLTableElement> tableElementList = new ArrayList<SQLTableElement>();
|
||||
|
||||
@Override
|
||||
public void accept0(SQLServerASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
acceptChild(visitor, this.name);
|
||||
acceptChild(visitor, this.dataType);
|
||||
acceptChild(visitor, this.value);
|
||||
acceptChild(visitor, this.tableElementList);
|
||||
}
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
public SQLExpr getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(SQLExpr name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public SQLDataType getDataType() {
|
||||
return dataType;
|
||||
}
|
||||
|
||||
public void setDataType(SQLDataType dataType) {
|
||||
this.dataType = dataType;
|
||||
}
|
||||
|
||||
public SQLExpr getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(SQLExpr value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public List<SQLTableElement> getTableElementList() {
|
||||
return tableElementList;
|
||||
}
|
||||
|
||||
public void setTableElementList(List<SQLTableElement> tableElementList) {
|
||||
this.tableElementList = tableElementList;
|
||||
}
|
||||
|
||||
public enum Type {
|
||||
TABLE, LOCAL, CURSOR;
|
||||
}
|
||||
|
||||
public Type getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(Type type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
}
|
||||
+4
-4
@@ -18,14 +18,14 @@ package com.alibaba.druid.sql.dialect.sqlserver.ast.stmt;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerDeclareItem;
|
||||
import com.alibaba.druid.sql.ast.SQLDeclareItem;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerObjectImpl;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.visitor.SQLServerASTVisitor;
|
||||
|
||||
public class SQLServerDeclareStatement extends SQLServerObjectImpl implements SQLServerStatement {
|
||||
|
||||
protected List<SQLServerDeclareItem> items = new ArrayList<SQLServerDeclareItem>();
|
||||
protected List<SQLDeclareItem> items = new ArrayList<SQLDeclareItem>();
|
||||
|
||||
private String dbType;
|
||||
|
||||
@@ -37,11 +37,11 @@ public class SQLServerDeclareStatement extends SQLServerObjectImpl implements SQ
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
public List<SQLServerDeclareItem> getItems() {
|
||||
public List<SQLDeclareItem> getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
public void setItems(List<SQLServerDeclareItem> items) {
|
||||
public void setItems(List<SQLDeclareItem> items) {
|
||||
this.items = items;
|
||||
}
|
||||
|
||||
|
||||
+5
-5
@@ -21,6 +21,7 @@ import java.util.List;
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLName;
|
||||
import com.alibaba.druid.sql.ast.SQLObject;
|
||||
import com.alibaba.druid.sql.ast.SQLDeclareItem;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLQueryExpr;
|
||||
@@ -34,7 +35,6 @@ import com.alibaba.druid.sql.ast.statement.SQLSetStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLTableElement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLTableSource;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLUpdateStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerDeclareItem;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerOutput;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerTop;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerCommitStatement;
|
||||
@@ -171,7 +171,7 @@ public class SQLServerStatementParser extends SQLStatementParser {
|
||||
SQLServerDeclareStatement declareStatement = new SQLServerDeclareStatement();
|
||||
|
||||
for (;;) {
|
||||
SQLServerDeclareItem item = new SQLServerDeclareItem();
|
||||
SQLDeclareItem item = new SQLDeclareItem();
|
||||
declareStatement.getItems().add(item);
|
||||
|
||||
item.setName(this.exprParser.name());
|
||||
@@ -182,7 +182,7 @@ public class SQLServerStatementParser extends SQLStatementParser {
|
||||
|
||||
if (lexer.token() == Token.TABLE) {
|
||||
lexer.nextToken();
|
||||
item.setType(SQLServerDeclareItem.Type.TABLE);
|
||||
item.setType(SQLDeclareItem.Type.TABLE);
|
||||
|
||||
if (lexer.token() == Token.LPAREN) {
|
||||
lexer.nextToken();
|
||||
@@ -221,10 +221,10 @@ public class SQLServerStatementParser extends SQLStatementParser {
|
||||
}
|
||||
break;
|
||||
} else if (lexer.token() == Token.CURSOR) {
|
||||
item.setType(SQLServerDeclareItem.Type.CURSOR);
|
||||
item.setType(SQLDeclareItem.Type.CURSOR);
|
||||
lexer.nextToken();
|
||||
} else {
|
||||
item.setType(SQLServerDeclareItem.Type.LOCAL);
|
||||
item.setType(SQLDeclareItem.Type.LOCAL);
|
||||
item.setDataType(this.exprParser.parseDataType());
|
||||
if (lexer.token() == Token.EQ) {
|
||||
lexer.nextToken();
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
package com.alibaba.druid.sql.dialect.sqlserver.visitor;
|
||||
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerColumnDefinition;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerDeclareItem;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerOutput;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerSelect;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerSelectQueryBlock;
|
||||
@@ -79,10 +78,6 @@ public interface SQLServerASTVisitor extends SQLASTVisitor {
|
||||
boolean visit(SQLServerOutput x);
|
||||
|
||||
void endVisit(SQLServerOutput x);
|
||||
|
||||
boolean visit(SQLServerDeclareItem x);
|
||||
|
||||
void endVisit(SQLServerDeclareItem x);
|
||||
|
||||
boolean visit(SQLServerDeclareStatement x);
|
||||
|
||||
|
||||
-11
@@ -16,7 +16,6 @@
|
||||
package com.alibaba.druid.sql.dialect.sqlserver.visitor;
|
||||
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerColumnDefinition;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerDeclareItem;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerOutput;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerSelect;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerSelectQueryBlock;
|
||||
@@ -146,16 +145,6 @@ public class SQLServerASTVisitorAdapter extends SQLASTVisitorAdapter implements
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLServerDeclareItem x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(SQLServerDeclareItem x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLServerDeclareStatement x) {
|
||||
return true;
|
||||
|
||||
-43
@@ -26,7 +26,6 @@ import com.alibaba.druid.sql.ast.statement.SQLExprTableSource;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLGrantStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerColumnDefinition;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerColumnDefinition.Identity;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerDeclareItem;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerOutput;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerSelect;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerSelectQueryBlock;
|
||||
@@ -429,48 +428,6 @@ public class SQLServerOutputVisitor extends SQLASTOutputVisitor implements SQLSe
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLServerDeclareItem x) {
|
||||
x.getName().accept(this);
|
||||
|
||||
if(x.getType() == SQLServerDeclareItem.Type.TABLE) {
|
||||
print0(ucase ? " TABLE" : " table");
|
||||
int size = x.getTableElementList().size();
|
||||
|
||||
if (size > 0) {
|
||||
print0(" (");
|
||||
incrementIndent();
|
||||
println();
|
||||
for (int i = 0; i < size; ++i) {
|
||||
if (i != 0) {
|
||||
print(',');
|
||||
println();
|
||||
}
|
||||
x.getTableElementList().get(i).accept(this);
|
||||
}
|
||||
decrementIndent();
|
||||
println();
|
||||
print(')');
|
||||
}
|
||||
} else if (x.getType() == SQLServerDeclareItem.Type.CURSOR) {
|
||||
print0(ucase ? " CURSOR" : " cursor");
|
||||
} else {
|
||||
print(' ');
|
||||
x.getDataType().accept(this);
|
||||
if (x.getValue() != null) {
|
||||
print0(" = ");
|
||||
x.getValue().accept(this);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(SQLServerDeclareItem x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLServerDeclareStatement x) {
|
||||
print0(ucase ? "DECLARE " : "declare ");
|
||||
|
||||
+2
-12
@@ -17,13 +17,13 @@ package com.alibaba.druid.sql.dialect.sqlserver.visitor;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLDeclareItem;
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLColumnDefinition;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLInsertStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerColumnDefinition;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerColumnDefinition.Identity;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerDeclareItem;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerOutput;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerSelect;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerSelectQueryBlock;
|
||||
@@ -176,19 +176,9 @@ public class SQLServerSchemaStatVisitor extends SchemaStatVisitor implements SQL
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLServerDeclareItem x) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(SQLServerDeclareItem x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLServerDeclareStatement x) {
|
||||
for (SQLServerDeclareItem item : x.getItems()) {
|
||||
for (SQLDeclareItem item : x.getItems()) {
|
||||
item.setParent(x);
|
||||
|
||||
SQLExpr name = item.getName();
|
||||
|
||||
Reference in New Issue
Block a user