mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improve mysql ddl parver
This commit is contained in:
+41
-5
@@ -21,11 +21,14 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLCommentHint;
|
||||
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.SQLPartitioningClause;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLCreateTableStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLExprTableSource;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelect;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.MySqlObjectImpl;
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlASTVisitor;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
@@ -34,7 +37,7 @@ public class MySqlCreateTableStatement extends SQLCreateTableStatement implement
|
||||
|
||||
private boolean ifNotExiists = false;
|
||||
|
||||
private Map<String, String> tableOptions = new LinkedHashMap<String, String>();
|
||||
private Map<String, SQLObject> tableOptions = new LinkedHashMap<String, SQLObject>();
|
||||
|
||||
protected SQLSelect query;
|
||||
|
||||
@@ -43,15 +46,16 @@ public class MySqlCreateTableStatement extends SQLCreateTableStatement implement
|
||||
private List<SQLCommentHint> hints = new ArrayList<SQLCommentHint>();
|
||||
|
||||
private SQLExprTableSource like;
|
||||
|
||||
|
||||
public MySqlCreateTableStatement(){
|
||||
|
||||
}
|
||||
|
||||
|
||||
public SQLExprTableSource getLike() {
|
||||
return like;
|
||||
}
|
||||
|
||||
|
||||
public void setLike(SQLName like) {
|
||||
this.setLike(new SQLExprTableSource(like));
|
||||
}
|
||||
@@ -71,7 +75,7 @@ public class MySqlCreateTableStatement extends SQLCreateTableStatement implement
|
||||
this.hints = hints;
|
||||
}
|
||||
|
||||
public void setTableOptions(Map<String, String> tableOptions) {
|
||||
public void setTableOptions(Map<String, SQLObject> tableOptions) {
|
||||
this.tableOptions = tableOptions;
|
||||
}
|
||||
|
||||
@@ -83,7 +87,7 @@ public class MySqlCreateTableStatement extends SQLCreateTableStatement implement
|
||||
this.partitioning = partitioning;
|
||||
}
|
||||
|
||||
public Map<String, String> getTableOptions() {
|
||||
public Map<String, SQLObject> getTableOptions() {
|
||||
return tableOptions;
|
||||
}
|
||||
|
||||
@@ -122,4 +126,36 @@ public class MySqlCreateTableStatement extends SQLCreateTableStatement implement
|
||||
}
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
public static class TableSpaceOption extends MySqlObjectImpl {
|
||||
|
||||
private SQLName name;
|
||||
private SQLExpr storage;
|
||||
|
||||
public SQLName getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(SQLName name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public SQLExpr getStorage() {
|
||||
return storage;
|
||||
}
|
||||
|
||||
public void setStorage(SQLExpr storage) {
|
||||
this.storage = storage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept0(MySqlASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
acceptChild(visitor, getName());
|
||||
acceptChild(visitor, getStorage());
|
||||
}
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* 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.dialect.mysql.ast.statement;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLName;
|
||||
import com.alibaba.druid.sql.ast.SQLPartitioningClause;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.MySqlObjectImpl;
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlASTVisitor;
|
||||
|
||||
public class MySqlPartitionByHash extends MySqlObjectImpl implements SQLPartitioningClause {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private SQLExpr expr;
|
||||
|
||||
private SQLExpr partitionCount;
|
||||
|
||||
@Override
|
||||
public void accept0(MySqlASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
acceptChild(visitor, expr);
|
||||
acceptChild(visitor, partitionCount);
|
||||
}
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
public SQLExpr getPartitionCount() {
|
||||
return partitionCount;
|
||||
}
|
||||
|
||||
public void setPartitionCount(SQLExpr partitionCount) {
|
||||
this.partitionCount = partitionCount;
|
||||
}
|
||||
|
||||
|
||||
public SQLExpr getExpr() {
|
||||
return expr;
|
||||
}
|
||||
|
||||
|
||||
public void setExpr(SQLExpr expr) {
|
||||
this.expr = expr;
|
||||
}
|
||||
}
|
||||
+60
-43
@@ -24,6 +24,8 @@ import com.alibaba.druid.sql.ast.statement.SQLTableConstaint;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.MySqlForeignKey;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.MySqlKey;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateTableStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateTableStatement.TableSpaceOption;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlPartitionByHash;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlPartitionByKey;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlTableIndex;
|
||||
import com.alibaba.druid.sql.parser.ParserException;
|
||||
@@ -156,8 +158,7 @@ public class MySqlCreateTableParser extends SQLCreateTableParser {
|
||||
if (lexer.token() == Token.EQ) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
stmt.getTableOptions().put("ENGINE", lexer.stringVal());
|
||||
lexer.nextToken();
|
||||
stmt.getTableOptions().put("ENGINE", this.exprParser.expr());
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -166,8 +167,7 @@ public class MySqlCreateTableParser extends SQLCreateTableParser {
|
||||
if (lexer.token() == Token.EQ) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
stmt.getTableOptions().put("AUTO_INCREMENT", lexer.numberString());
|
||||
lexer.nextToken();
|
||||
stmt.getTableOptions().put("AUTO_INCREMENT", this.exprParser.expr());
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -176,8 +176,7 @@ public class MySqlCreateTableParser extends SQLCreateTableParser {
|
||||
if (lexer.token() == Token.EQ) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
stmt.getTableOptions().put("AVG_ROW_LENGTH", lexer.numberString());
|
||||
lexer.nextToken();
|
||||
stmt.getTableOptions().put("AVG_ROW_LENGTH", this.exprParser.expr());
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -196,8 +195,7 @@ public class MySqlCreateTableParser extends SQLCreateTableParser {
|
||||
if (lexer.token() == Token.EQ) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
stmt.getTableOptions().put("CHECKSUM", lexer.numberString());
|
||||
lexer.nextToken();
|
||||
stmt.getTableOptions().put("CHECKSUM", this.exprParser.expr());
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -206,8 +204,7 @@ public class MySqlCreateTableParser extends SQLCreateTableParser {
|
||||
if (lexer.token() == Token.EQ) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
stmt.getTableOptions().put("COMMENT", lexer.stringVal());
|
||||
lexer.nextToken();
|
||||
stmt.getTableOptions().put("COMMENT", this.exprParser.expr());
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -216,8 +213,7 @@ public class MySqlCreateTableParser extends SQLCreateTableParser {
|
||||
if (lexer.token() == Token.EQ) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
stmt.getTableOptions().put("CONNECTION", lexer.stringVal());
|
||||
lexer.nextToken();
|
||||
stmt.getTableOptions().put("CONNECTION", this.exprParser.expr());
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -227,8 +223,7 @@ public class MySqlCreateTableParser extends SQLCreateTableParser {
|
||||
if (lexer.token() == Token.EQ) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
stmt.getTableOptions().put("DATA DIRECTORY", lexer.stringVal());
|
||||
lexer.nextToken();
|
||||
stmt.getTableOptions().put("DATA DIRECTORY", this.exprParser.expr());
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -237,8 +232,7 @@ public class MySqlCreateTableParser extends SQLCreateTableParser {
|
||||
if (lexer.token() == Token.EQ) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
stmt.getTableOptions().put("DELAY_KEY_WRITE", lexer.stringVal());
|
||||
lexer.nextToken();
|
||||
stmt.getTableOptions().put("DELAY_KEY_WRITE", this.exprParser.expr());
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -248,8 +242,7 @@ public class MySqlCreateTableParser extends SQLCreateTableParser {
|
||||
if (lexer.token() == Token.EQ) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
stmt.getTableOptions().put("INDEX DIRECTORY", lexer.stringVal());
|
||||
lexer.nextToken();
|
||||
stmt.getTableOptions().put("INDEX DIRECTORY", this.exprParser.expr());
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -258,8 +251,7 @@ public class MySqlCreateTableParser extends SQLCreateTableParser {
|
||||
if (lexer.token() == Token.EQ) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
stmt.getTableOptions().put("INSERT_METHOD", lexer.stringVal());
|
||||
lexer.nextToken();
|
||||
stmt.getTableOptions().put("INSERT_METHOD", this.exprParser.expr());
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -268,8 +260,7 @@ public class MySqlCreateTableParser extends SQLCreateTableParser {
|
||||
if (lexer.token() == Token.EQ) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
stmt.getTableOptions().put("KEY_BLOCK_SIZE", lexer.stringVal());
|
||||
lexer.nextToken();
|
||||
stmt.getTableOptions().put("KEY_BLOCK_SIZE", this.exprParser.expr());
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -278,8 +269,7 @@ public class MySqlCreateTableParser extends SQLCreateTableParser {
|
||||
if (lexer.token() == Token.EQ) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
stmt.getTableOptions().put("MAX_ROWS", lexer.stringVal());
|
||||
lexer.nextToken();
|
||||
stmt.getTableOptions().put("MAX_ROWS", this.exprParser.expr());
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -288,8 +278,7 @@ public class MySqlCreateTableParser extends SQLCreateTableParser {
|
||||
if (lexer.token() == Token.EQ) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
stmt.getTableOptions().put("MIN_ROWS", lexer.stringVal());
|
||||
lexer.nextToken();
|
||||
stmt.getTableOptions().put("MIN_ROWS", this.exprParser.expr());
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -298,8 +287,7 @@ public class MySqlCreateTableParser extends SQLCreateTableParser {
|
||||
if (lexer.token() == Token.EQ) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
stmt.getTableOptions().put("PACK_KEYS", lexer.stringVal());
|
||||
lexer.nextToken();
|
||||
stmt.getTableOptions().put("PACK_KEYS", this.exprParser.expr());
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -308,8 +296,7 @@ public class MySqlCreateTableParser extends SQLCreateTableParser {
|
||||
if (lexer.token() == Token.EQ) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
stmt.getTableOptions().put("PASSWORD", lexer.stringVal());
|
||||
lexer.nextToken();
|
||||
stmt.getTableOptions().put("PASSWORD", this.exprParser.expr());
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -318,29 +305,49 @@ public class MySqlCreateTableParser extends SQLCreateTableParser {
|
||||
if (lexer.token() == Token.EQ) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
stmt.getTableOptions().put("ROW_FORMAT", lexer.stringVal());
|
||||
stmt.getTableOptions().put("ROW_FORMAT", this.exprParser.expr());
|
||||
continue;
|
||||
}
|
||||
|
||||
if (identifierEquals("STATS_AUTO_RECALC")) {
|
||||
lexer.nextToken();
|
||||
if (lexer.token() == Token.EQ) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
stmt.getTableOptions().put("STATS_AUTO_RECALC", this.exprParser.expr());
|
||||
continue;
|
||||
}
|
||||
|
||||
if (identifierEquals("STATS_PERSISTENT")) {
|
||||
lexer.nextToken();
|
||||
if (lexer.token() == Token.EQ) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
stmt.getTableOptions().put("STATS_PERSISTENT", this.exprParser.expr());
|
||||
continue;
|
||||
}
|
||||
|
||||
if (identifierEquals("TABLESPACE")) {
|
||||
lexer.nextToken();
|
||||
|
||||
String tablespace_name = lexer.stringVal();
|
||||
accept(Token.IDENTIFIER);
|
||||
TableSpaceOption option = new TableSpaceOption();
|
||||
option.setName(this.exprParser.name());
|
||||
|
||||
if (identifierEquals("STORAGE")) {
|
||||
throw new ParserException("TODO STORAGE");
|
||||
lexer.nextToken();
|
||||
option.setStorage(this.exprParser.name());
|
||||
}
|
||||
|
||||
stmt.getTableOptions().put("TABLESPACE", tablespace_name);
|
||||
|
||||
stmt.getTableOptions().put("TABLESPACE", option);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (identifierEquals("TYPE")) {
|
||||
lexer.nextToken();
|
||||
accept(Token.EQ);
|
||||
stmt.getTableOptions().put("TYPE", lexer.stringVal());
|
||||
stmt.getTableOptions().put("TYPE", this.exprParser.expr());
|
||||
lexer.nextToken();
|
||||
continue;
|
||||
}
|
||||
@@ -364,6 +371,19 @@ public class MySqlCreateTableParser extends SQLCreateTableParser {
|
||||
accept(Token.RPAREN);
|
||||
stmt.setPartitioning(clause);
|
||||
|
||||
if (identifierEquals("PARTITIONS")) {
|
||||
lexer.nextToken();
|
||||
clause.setPartitionCount(this.exprParser.expr());
|
||||
}
|
||||
} else if (identifierEquals("HASH")) {
|
||||
lexer.nextToken();
|
||||
MySqlPartitionByHash clause = new MySqlPartitionByHash();
|
||||
|
||||
accept(Token.LPAREN);
|
||||
clause.setExpr(this.exprParser.expr());
|
||||
accept(Token.RPAREN);
|
||||
stmt.setPartitioning(clause);
|
||||
|
||||
if (identifierEquals("PARTITIONS")) {
|
||||
lexer.nextToken();
|
||||
clause.setPartitionCount(this.exprParser.expr());
|
||||
@@ -395,8 +415,7 @@ public class MySqlCreateTableParser extends SQLCreateTableParser {
|
||||
if (lexer.token() == Token.EQ) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
stmt.getTableOptions().put("CHARACTER SET", lexer.stringVal());
|
||||
lexer.nextToken();
|
||||
stmt.getTableOptions().put("CHARACTER SET", this.exprParser.expr());
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -405,8 +424,7 @@ public class MySqlCreateTableParser extends SQLCreateTableParser {
|
||||
if (lexer.token() == Token.EQ) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
stmt.getTableOptions().put("CHARSET", lexer.stringVal());
|
||||
lexer.nextToken();
|
||||
stmt.getTableOptions().put("CHARSET", this.exprParser.expr());
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -415,8 +433,7 @@ public class MySqlCreateTableParser extends SQLCreateTableParser {
|
||||
if (lexer.token() == Token.EQ) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
stmt.getTableOptions().put("COLLATE", lexer.stringVal());
|
||||
lexer.nextToken();
|
||||
stmt.getTableOptions().put("COLLATE", this.exprParser.expr());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -58,6 +58,7 @@ import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlKillStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlLoadDataInFileStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlLoadXmlStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlLockTableStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlPartitionByHash;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlPartitionByKey;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlPrepareStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlRenameTableStatement;
|
||||
@@ -540,4 +541,12 @@ public interface MySqlASTVisitor extends SQLASTVisitor {
|
||||
boolean visit(MySqlAlterTableImportTablespace x);
|
||||
|
||||
void endVisit(MySqlAlterTableImportTablespace x);
|
||||
|
||||
boolean visit(MySqlCreateTableStatement.TableSpaceOption x);
|
||||
|
||||
void endVisit(MySqlCreateTableStatement.TableSpaceOption x);
|
||||
|
||||
boolean visit(MySqlPartitionByHash x);
|
||||
|
||||
void endVisit(MySqlPartitionByHash x);
|
||||
} //
|
||||
|
||||
@@ -45,6 +45,7 @@ import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlBinlogStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCommitStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateIndexStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateTableStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateTableStatement.TableSpaceOption;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateUserStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateUserStatement.UserSpecification;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlDeleteStatement;
|
||||
@@ -59,6 +60,7 @@ import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlKillStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlLoadDataInFileStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlLoadXmlStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlLockTableStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlPartitionByHash;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlPartitionByKey;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlPrepareStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlRenameTableStatement;
|
||||
@@ -1193,4 +1195,24 @@ public class MySqlASTVisitorAdapter extends SQLASTVisitorAdapter implements
|
||||
public void endVisit(MySqlAlterTableImportTablespace x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(TableSpaceOption x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(TableSpaceOption x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlPartitionByHash x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(MySqlPartitionByHash x) {
|
||||
|
||||
}
|
||||
} //
|
||||
|
||||
@@ -21,6 +21,7 @@ import java.util.Map;
|
||||
import com.alibaba.druid.sql.ast.SQLCommentHint;
|
||||
import com.alibaba.druid.sql.ast.SQLDataType;
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLObject;
|
||||
import com.alibaba.druid.sql.ast.SQLSetQuantifier;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLCharExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLMethodInvokeExpr;
|
||||
@@ -64,6 +65,7 @@ import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlBinlogStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCommitStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateIndexStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateTableStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateTableStatement.TableSpaceOption;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateUserStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateUserStatement.UserSpecification;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlDeleteStatement;
|
||||
@@ -78,6 +80,7 @@ import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlKillStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlLoadDataInFileStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlLoadXmlStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlLockTableStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlPartitionByHash;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlPartitionByKey;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlPrepareStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlRenameTableStatement;
|
||||
@@ -295,7 +298,7 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
x.getDefaultExpr().accept(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (mysqlColumn != null && mysqlColumn.getStorage() != null) {
|
||||
print(" STORAGE ");
|
||||
mysqlColumn.getStorage().accept(this);
|
||||
@@ -431,12 +434,12 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
}
|
||||
|
||||
x.getName().accept(this);
|
||||
|
||||
|
||||
if (x.getLike() != null) {
|
||||
print(" LIKE ");
|
||||
x.getLike().accept(this);
|
||||
}
|
||||
|
||||
|
||||
int size = x.getTableElementList().size();
|
||||
if (size > 0) {
|
||||
print(" (");
|
||||
@@ -454,37 +457,29 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
print(")");
|
||||
}
|
||||
|
||||
for (Map.Entry<String, String> option : x.getTableOptions().entrySet()) {
|
||||
for (Map.Entry<String, SQLObject> option : x.getTableOptions().entrySet()) {
|
||||
String key = option.getKey();
|
||||
|
||||
print(' ');
|
||||
print(key);
|
||||
|
||||
|
||||
if ("TABLESPACE".equals(key)) {
|
||||
print(' ');
|
||||
print(option.getValue());
|
||||
option.getValue().accept(this);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
print(" = ");
|
||||
|
||||
if ("COMMENT".equals(key)) {
|
||||
new SQLCharExpr(option.getValue()).accept(this);
|
||||
} else if ("CONNECTION".equals(key)) {
|
||||
new SQLCharExpr(option.getValue()).accept(this);
|
||||
} else if ("DATA DIRECTORY".equals(key)) {
|
||||
new SQLCharExpr(option.getValue()).accept(this);
|
||||
} else if ("INDEX DIRECTORY".equals(key)) {
|
||||
new SQLCharExpr(option.getValue()).accept(this);
|
||||
} else if ("PASSWORD".equals(key)) {
|
||||
new SQLCharExpr(option.getValue()).accept(this);
|
||||
} else {
|
||||
print(option.getValue());
|
||||
}
|
||||
option.getValue().accept(this);
|
||||
}
|
||||
|
||||
if (x.getPartitioning() != null) {
|
||||
print(' ');
|
||||
x.getPartitioning().accept(this);
|
||||
}
|
||||
|
||||
if (x.getQuery() != null) {
|
||||
print(" ");
|
||||
incrementIndent();
|
||||
println();
|
||||
x.getQuery().accept(this);
|
||||
@@ -1512,6 +1507,24 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(MySqlPartitionByHash x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlPartitionByHash x) {
|
||||
print("PARTITION BY HASH (");
|
||||
x.getExpr().accept(this);
|
||||
print(")");
|
||||
|
||||
if (x.getPartitionCount() != null) {
|
||||
print(" PARTITIONS ");
|
||||
x.getPartitionCount().accept(this);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(MySqlSelectQueryBlock x) {
|
||||
|
||||
@@ -2867,4 +2880,20 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
x.getValue().accept(this);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(TableSpaceOption x) {
|
||||
x.getName().accept(this);
|
||||
|
||||
if (x.getStorage() != null) {
|
||||
print(' ');
|
||||
x.getStorage().accept(this);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(TableSpaceOption x) {
|
||||
|
||||
}
|
||||
} //
|
||||
|
||||
@@ -58,6 +58,7 @@ import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlBinlogStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCommitStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateIndexStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateTableStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateTableStatement.TableSpaceOption;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateUserStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateUserStatement.UserSpecification;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlDeleteStatement;
|
||||
@@ -72,6 +73,7 @@ import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlKillStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlLoadDataInFileStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlLoadXmlStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlLockTableStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlPartitionByHash;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlPartitionByKey;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlPrepareStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlRenameTableStatement;
|
||||
@@ -1277,4 +1279,24 @@ public class MySqlSchemaStatVisitor extends SchemaStatVisitor implements MySqlAS
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(TableSpaceOption x) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(TableSpaceOption x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlPartitionByHash x) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(MySqlPartitionByHash x) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user