mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improve mysql ddl parser
This commit is contained in:
+11
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.alibaba.druid.sql.dialect.mysql.ast.statement;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLColumnDefinition;
|
||||
|
||||
public class MySqlSQLColumnDefinition extends SQLColumnDefinition {
|
||||
@@ -23,6 +24,8 @@ public class MySqlSQLColumnDefinition extends SQLColumnDefinition {
|
||||
|
||||
private boolean autoIncrement = false;
|
||||
|
||||
private SQLExpr onUpdate;
|
||||
|
||||
public MySqlSQLColumnDefinition(){
|
||||
|
||||
}
|
||||
@@ -35,4 +38,12 @@ public class MySqlSQLColumnDefinition extends SQLColumnDefinition {
|
||||
this.autoIncrement = autoIncrement;
|
||||
}
|
||||
|
||||
|
||||
public SQLExpr getOnUpdate() {
|
||||
return onUpdate;
|
||||
}
|
||||
|
||||
public void setOnUpdate(SQLExpr onUpdate) {
|
||||
this.onUpdate = onUpdate;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -530,6 +530,13 @@ public class MySqlExprParser extends SQLExprParser {
|
||||
}
|
||||
|
||||
public SQLColumnDefinition parseColumnRest(SQLColumnDefinition column) {
|
||||
if (lexer.token() == Token.ON) {
|
||||
lexer.nextToken();
|
||||
accept(Token.UPDATE);
|
||||
SQLExpr expr = this.expr();
|
||||
((MySqlSQLColumnDefinition) column).setOnUpdate(expr);
|
||||
}
|
||||
|
||||
if (identifierEquals("AUTO_INCREMENT")) {
|
||||
lexer.nextToken();
|
||||
if (column instanceof MySqlSQLColumnDefinition) {
|
||||
|
||||
@@ -295,7 +295,13 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
x.getDefaultExpr().accept(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (mysqlColumn != null && mysqlColumn.getOnUpdate() != null) {
|
||||
print(" ON UPDATE ");
|
||||
|
||||
mysqlColumn.getOnUpdate().accept(this);
|
||||
}
|
||||
|
||||
if (mysqlColumn != null && mysqlColumn.isAutoIncrement()) {
|
||||
print(" AUTO_INCREMENT");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user