mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improve mysql ddl parser support
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright 1999-2011 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.SQLObjectImpl;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class SQLAlterTableAlterColumn extends SQLObjectImpl implements SQLAlterTableItem {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private SQLColumnDefinition column;
|
||||
|
||||
@Override
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
acceptChild(visitor, column);
|
||||
}
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
public SQLColumnDefinition getColumn() {
|
||||
return column;
|
||||
}
|
||||
|
||||
public void setColumn(SQLColumnDefinition column) {
|
||||
this.column = column;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -30,6 +30,7 @@ import com.alibaba.druid.sql.ast.expr.SQLLiteralExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLQueryExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLVariantRefExpr;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableAddPrimaryKey;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableAlterColumn;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableDropColumnItem;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableDropIndex;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLColumnDefinition;
|
||||
@@ -2213,7 +2214,16 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
stmt.getItems().add(item);
|
||||
}
|
||||
} else if (lexer.token() == Token.ALTER) {
|
||||
throw new ParserException("TODO " + lexer.token() + " " + lexer.stringVal());
|
||||
lexer.nextToken();
|
||||
if (identifierEquals("COLUMN")) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
SQLAlterTableAlterColumn alterColumn = new SQLAlterTableAlterColumn();
|
||||
SQLColumnDefinition columnDef = this.exprParser.parseColumn();
|
||||
alterColumn.setColumn(columnDef);
|
||||
|
||||
stmt.getItems().add(alterColumn);
|
||||
} else if (identifierEquals("CHANGE")) {
|
||||
lexer.nextToken();
|
||||
if (identifierEquals("COLUMN")) {
|
||||
|
||||
@@ -67,6 +67,7 @@ import com.alibaba.druid.sql.ast.expr.SQLVariantRefExpr;
|
||||
import com.alibaba.druid.sql.ast.statement.NotNullConstraint;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableAddColumn;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableAddPrimaryKey;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableAlterColumn;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableDropColumnItem;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableDropIndex;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAssignItem;
|
||||
@@ -1353,4 +1354,11 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLAlterTableAlterColumn x) {
|
||||
print("ALTER COLUMN ");
|
||||
x.getColumn().accept(this);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,6 +55,7 @@ import com.alibaba.druid.sql.ast.expr.SQLVariantRefExpr;
|
||||
import com.alibaba.druid.sql.ast.statement.NotNullConstraint;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableAddColumn;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableAddPrimaryKey;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableAlterColumn;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableDropColumnItem;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableDropIndex;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAssignItem;
|
||||
@@ -251,7 +252,7 @@ public interface SQLASTVisitor {
|
||||
boolean visit(SQLDataType x);
|
||||
|
||||
void endVisit(SQLDataType x);
|
||||
|
||||
|
||||
boolean visit(SQLCharactorDataType x);
|
||||
|
||||
void endVisit(SQLCharactorDataType x);
|
||||
@@ -363,13 +364,13 @@ public interface SQLASTVisitor {
|
||||
boolean visit(SQLAlterTableDropColumnItem x);
|
||||
|
||||
void endVisit(SQLAlterTableDropColumnItem x);
|
||||
|
||||
|
||||
boolean visit(SQLAlterTableDropIndex x);
|
||||
|
||||
|
||||
void endVisit(SQLAlterTableDropIndex x);
|
||||
|
||||
|
||||
boolean visit(SQLAlterTableAddPrimaryKey x);
|
||||
|
||||
|
||||
void endVisit(SQLAlterTableAddPrimaryKey x);
|
||||
|
||||
boolean visit(SQLDropIndexStatement x);
|
||||
@@ -399,24 +400,28 @@ public interface SQLASTVisitor {
|
||||
void endVisit(SQLCreateDatabaseStatement x);
|
||||
|
||||
boolean visit(SQLCreateDatabaseStatement x);
|
||||
|
||||
|
||||
void endVisit(SQLOver x);
|
||||
|
||||
|
||||
boolean visit(SQLOver x);
|
||||
|
||||
|
||||
void endVisit(SQLColumnPrimaryKey x);
|
||||
|
||||
|
||||
boolean visit(SQLColumnPrimaryKey x);
|
||||
|
||||
|
||||
void endVisit(SQLColumnUniqueIndex x);
|
||||
|
||||
|
||||
boolean visit(SQLColumnUniqueIndex x);
|
||||
|
||||
|
||||
void endVisit(SQLWithSubqueryClause x);
|
||||
|
||||
|
||||
boolean visit(SQLWithSubqueryClause x);
|
||||
|
||||
|
||||
void endVisit(SQLWithSubqueryClause.Entry x);
|
||||
|
||||
|
||||
boolean visit(SQLWithSubqueryClause.Entry x);
|
||||
|
||||
void endVisit(SQLAlterTableAlterColumn x);
|
||||
|
||||
boolean visit(SQLAlterTableAlterColumn x);
|
||||
}
|
||||
|
||||
@@ -55,6 +55,7 @@ import com.alibaba.druid.sql.ast.expr.SQLVariantRefExpr;
|
||||
import com.alibaba.druid.sql.ast.statement.NotNullConstraint;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableAddColumn;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableAddPrimaryKey;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableAlterColumn;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableDropColumnItem;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableDropIndex;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAssignItem;
|
||||
@@ -765,4 +766,14 @@ public class SQLASTVisitorAdapter implements SQLASTVisitor {
|
||||
public void endVisit(SQLCharactorDataType x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(SQLAlterTableAlterColumn x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLAlterTableAlterColumn x) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user