mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improve mysql parser
This commit is contained in:
+1
-1
@@ -43,7 +43,7 @@ public class MySqlCreateTableStatement extends SQLCreateTableStatement implement
|
||||
private List<SQLCommentHint> hints = new ArrayList<SQLCommentHint>();
|
||||
|
||||
private SQLExprTableSource like;
|
||||
|
||||
|
||||
public MySqlCreateTableStatement(){
|
||||
|
||||
}
|
||||
|
||||
+13
-2
@@ -26,6 +26,8 @@ public class MySqlSQLColumnDefinition extends SQLColumnDefinition {
|
||||
|
||||
private SQLExpr onUpdate;
|
||||
|
||||
private SQLExpr storage;
|
||||
|
||||
public MySqlSQLColumnDefinition(){
|
||||
|
||||
}
|
||||
@@ -38,12 +40,21 @@ public class MySqlSQLColumnDefinition extends SQLColumnDefinition {
|
||||
this.autoIncrement = autoIncrement;
|
||||
}
|
||||
|
||||
|
||||
public SQLExpr getOnUpdate() {
|
||||
return onUpdate;
|
||||
}
|
||||
|
||||
|
||||
public void setOnUpdate(SQLExpr onUpdate) {
|
||||
this.onUpdate = onUpdate;
|
||||
}
|
||||
|
||||
|
||||
public SQLExpr getStorage() {
|
||||
return storage;
|
||||
}
|
||||
|
||||
|
||||
public void setStorage(SQLExpr storage) {
|
||||
this.storage = storage;
|
||||
}
|
||||
}
|
||||
|
||||
+30
-16
@@ -186,7 +186,7 @@ public class MySqlCreateTableParser extends SQLCreateTableParser {
|
||||
parseTableOptionCharsetOrCollate(stmt);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (parseTableOptionCharsetOrCollate(stmt)) {
|
||||
continue;
|
||||
}
|
||||
@@ -200,7 +200,7 @@ public class MySqlCreateTableParser extends SQLCreateTableParser {
|
||||
lexer.nextToken();
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (identifierEquals("COMMENT")) {
|
||||
lexer.nextToken();
|
||||
if (lexer.token() == Token.EQ) {
|
||||
@@ -210,7 +210,7 @@ public class MySqlCreateTableParser extends SQLCreateTableParser {
|
||||
lexer.nextToken();
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (identifierEquals("CONNECTION")) {
|
||||
lexer.nextToken();
|
||||
if (lexer.token() == Token.EQ) {
|
||||
@@ -220,7 +220,7 @@ public class MySqlCreateTableParser extends SQLCreateTableParser {
|
||||
lexer.nextToken();
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (identifierEquals("DATA")) {
|
||||
lexer.nextToken();
|
||||
acceptIdentifier("DIRECTORY");
|
||||
@@ -231,7 +231,7 @@ public class MySqlCreateTableParser extends SQLCreateTableParser {
|
||||
lexer.nextToken();
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (identifierEquals("DELAY_KEY_WRITE")) {
|
||||
lexer.nextToken();
|
||||
if (lexer.token() == Token.EQ) {
|
||||
@@ -241,7 +241,7 @@ public class MySqlCreateTableParser extends SQLCreateTableParser {
|
||||
lexer.nextToken();
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (identifierEquals("INDEX")) {
|
||||
lexer.nextToken();
|
||||
acceptIdentifier("DIRECTORY");
|
||||
@@ -252,7 +252,7 @@ public class MySqlCreateTableParser extends SQLCreateTableParser {
|
||||
lexer.nextToken();
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (identifierEquals("INSERT_METHOD")) {
|
||||
lexer.nextToken();
|
||||
if (lexer.token() == Token.EQ) {
|
||||
@@ -262,7 +262,7 @@ public class MySqlCreateTableParser extends SQLCreateTableParser {
|
||||
lexer.nextToken();
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (identifierEquals("KEY_BLOCK_SIZE")) {
|
||||
lexer.nextToken();
|
||||
if (lexer.token() == Token.EQ) {
|
||||
@@ -272,7 +272,7 @@ public class MySqlCreateTableParser extends SQLCreateTableParser {
|
||||
lexer.nextToken();
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (identifierEquals("MAX_ROWS")) {
|
||||
lexer.nextToken();
|
||||
if (lexer.token() == Token.EQ) {
|
||||
@@ -282,7 +282,7 @@ public class MySqlCreateTableParser extends SQLCreateTableParser {
|
||||
lexer.nextToken();
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (identifierEquals("MIN_ROWS")) {
|
||||
lexer.nextToken();
|
||||
if (lexer.token() == Token.EQ) {
|
||||
@@ -292,7 +292,7 @@ public class MySqlCreateTableParser extends SQLCreateTableParser {
|
||||
lexer.nextToken();
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (identifierEquals("PACK_KEYS")) {
|
||||
lexer.nextToken();
|
||||
if (lexer.token() == Token.EQ) {
|
||||
@@ -302,7 +302,7 @@ public class MySqlCreateTableParser extends SQLCreateTableParser {
|
||||
lexer.nextToken();
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (identifierEquals("PASSWORD")) {
|
||||
lexer.nextToken();
|
||||
if (lexer.token() == Token.EQ) {
|
||||
@@ -312,7 +312,7 @@ public class MySqlCreateTableParser extends SQLCreateTableParser {
|
||||
lexer.nextToken();
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (identifierEquals("ROW_FORMAT")) {
|
||||
lexer.nextToken();
|
||||
if (lexer.token() == Token.EQ) {
|
||||
@@ -323,6 +323,20 @@ public class MySqlCreateTableParser extends SQLCreateTableParser {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (identifierEquals("TABLESPACE")) {
|
||||
lexer.nextToken();
|
||||
|
||||
String tablespace_name = lexer.stringVal();
|
||||
accept(Token.IDENTIFIER);
|
||||
|
||||
if (identifierEquals("STORAGE")) {
|
||||
throw new ParserException("TODO STORAGE");
|
||||
}
|
||||
|
||||
stmt.getTableOptions().put("TABLESPACE", tablespace_name);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (identifierEquals("TYPE")) {
|
||||
lexer.nextToken();
|
||||
accept(Token.EQ);
|
||||
@@ -373,7 +387,7 @@ public class MySqlCreateTableParser extends SQLCreateTableParser {
|
||||
|
||||
return stmt;
|
||||
}
|
||||
|
||||
|
||||
private boolean parseTableOptionCharsetOrCollate(MySqlCreateTableStatement stmt) {
|
||||
if (identifierEquals("CHARACTER")) {
|
||||
lexer.nextToken();
|
||||
@@ -395,7 +409,7 @@ public class MySqlCreateTableParser extends SQLCreateTableParser {
|
||||
lexer.nextToken();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
if (identifierEquals("COLLATE")) {
|
||||
lexer.nextToken();
|
||||
if (lexer.token() == Token.EQ) {
|
||||
@@ -405,7 +419,7 @@ public class MySqlCreateTableParser extends SQLCreateTableParser {
|
||||
lexer.nextToken();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -559,6 +559,14 @@ public class MySqlExprParser extends SQLExprParser {
|
||||
accept(Token.LITERAL_CHARS);
|
||||
}
|
||||
|
||||
if (identifierEquals("STORAGE")) {
|
||||
lexer.nextToken();
|
||||
SQLExpr expr = expr();
|
||||
if (column instanceof MySqlSQLColumnDefinition) {
|
||||
((MySqlSQLColumnDefinition) column).setStorage(expr);
|
||||
}
|
||||
}
|
||||
|
||||
super.parseColumnRest(column);
|
||||
|
||||
return column;
|
||||
|
||||
@@ -295,6 +295,11 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
x.getDefaultExpr().accept(this);
|
||||
}
|
||||
}
|
||||
|
||||
if (mysqlColumn != null && mysqlColumn.getStorage() != null) {
|
||||
print(" STORAGE ");
|
||||
mysqlColumn.getStorage().accept(this);
|
||||
}
|
||||
|
||||
if (mysqlColumn != null && mysqlColumn.getOnUpdate() != null) {
|
||||
print(" ON UPDATE ");
|
||||
@@ -452,8 +457,15 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
for (Map.Entry<String, String> option : x.getTableOptions().entrySet()) {
|
||||
String key = option.getKey();
|
||||
|
||||
print(" ");
|
||||
print(' ');
|
||||
print(key);
|
||||
|
||||
if ("TABLESPACE".equals(key)) {
|
||||
print(' ');
|
||||
print(option.getValue());
|
||||
continue;
|
||||
}
|
||||
|
||||
print(" = ");
|
||||
|
||||
if ("COMMENT".equals(key)) {
|
||||
|
||||
Reference in New Issue
Block a user