支持mysql create/alter列中包含charset的解析

This commit is contained in:
tivenwang
2015-10-31 14:06:11 +08:00
parent ca84a3ff95
commit 1f9e7aa798
5 changed files with 90 additions and 3 deletions
@@ -53,8 +53,9 @@ public class MySqlCharExpr extends SQLCharExpr implements MySqlExpr {
buf.append(charset);
buf.append(' ');
}
super.output(buf);
if (super.text!=null){
super.output(buf);
}
if (collate != null) {
buf.append(" COLLATE ");
@@ -26,10 +26,21 @@ public class MySqlSQLColumnDefinition extends SQLColumnDefinition {
private SQLExpr storage;
private SQLExpr charsetExpr;
public MySqlSQLColumnDefinition(){
}
public SQLExpr getCharsetExpr() {
return charsetExpr;
}
public void setCharsetExpr(SQLExpr charsetExpr) {
this.charsetExpr = charsetExpr;
}
public boolean isAutoIncrement() {
return autoIncrement;
}
@@ -531,7 +531,19 @@ public class MySqlExprParser extends SQLExprParser {
SQLExpr expr = this.expr();
((MySqlSQLColumnDefinition) column).setOnUpdate(expr);
}
if (identifierEquals("CHARSET")) {
lexer.nextToken();
MySqlCharExpr charSetCollateExpr=new MySqlCharExpr();
charSetCollateExpr.setCharset(lexer.stringVal());
lexer.nextToken();
if (identifierEquals("COLLATE")) {
lexer.nextToken();
charSetCollateExpr.setCollate(lexer.stringVal());
lexer.nextToken();
}
((MySqlSQLColumnDefinition) column).setCharsetExpr(charSetCollateExpr);
return parseColumnRest(column);
}
if (identifierEquals("AUTO_INCREMENT")) {
lexer.nextToken();
if (column instanceof MySqlSQLColumnDefinition) {
@@ -309,6 +309,11 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
print(' ');
x.getDataType().accept(this);
if (mysqlColumn != null && mysqlColumn.getCharsetExpr() != null) {
print(" CHARSET ");
mysqlColumn.getCharsetExpr().accept(this);
}
for (SQLColumnConstraint item : x.getConstraints()) {
print(' ');
item.accept(this);