mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improved mysql parser, fix #4300
This commit is contained in:
@@ -23,6 +23,7 @@ import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
public class SQLColumnCheck extends SQLConstraintImpl implements SQLColumnConstraint, SQLReplaceable {
|
||||
|
||||
private SQLExpr expr;
|
||||
protected Boolean enforced;
|
||||
|
||||
public SQLColumnCheck(){
|
||||
|
||||
@@ -43,6 +44,14 @@ public class SQLColumnCheck extends SQLConstraintImpl implements SQLColumnConstr
|
||||
this.expr = expr;
|
||||
}
|
||||
|
||||
public Boolean getEnforced() {
|
||||
return enforced;
|
||||
}
|
||||
|
||||
public void setEnforced(Boolean enforced) {
|
||||
this.enforced = enforced;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
|
||||
@@ -701,11 +701,17 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
}
|
||||
print(')');
|
||||
|
||||
if (x.getIndexDefinition().hasOptions()) {
|
||||
x.getIndexDefinition().getOptions().accept(this);
|
||||
SQLIndexDefinition indexDefinition = x.getIndexDefinition();
|
||||
if (indexDefinition.hasOptions()) {
|
||||
indexDefinition.getOptions().accept(this);
|
||||
}
|
||||
|
||||
SQLExpr comment = x.getComment();
|
||||
if (indexDefinition.hasOptions()
|
||||
&& indexDefinition.getOptions().getComment() == comment) {
|
||||
comment = null;
|
||||
}
|
||||
|
||||
if (comment != null) {
|
||||
print0(ucase ? " COMMENT " : " comment ");
|
||||
printExpr(comment);
|
||||
|
||||
@@ -4451,7 +4451,7 @@ public class SQLExprParser extends SQLParser {
|
||||
|
||||
protected SQLColumnCheck parseColumnCheck() {
|
||||
lexer.nextToken();
|
||||
SQLExpr expr = this.expr();
|
||||
SQLExpr expr = this.primary();
|
||||
SQLColumnCheck check = new SQLColumnCheck(expr);
|
||||
|
||||
if (lexer.token == Token.DISABLE) {
|
||||
@@ -4472,7 +4472,20 @@ public class SQLExprParser extends SQLParser {
|
||||
} else if (lexer.identifierEquals(FnvHash.Constants.NORELY)) {
|
||||
lexer.nextToken();
|
||||
check.setRely(Boolean.FALSE);
|
||||
} else if (lexer.identifierEquals("ENFORCED")) {
|
||||
lexer.nextToken();
|
||||
check.setEnforced(true);
|
||||
} else if (lexer.token == Token.NOT) {
|
||||
Lexer.SavePoint mark = lexer.mark();
|
||||
lexer.nextToken();
|
||||
if (lexer.identifierEquals("ENFORCED")) {
|
||||
lexer.nextToken();
|
||||
check.setEnforced(false);
|
||||
} else {
|
||||
lexer.reset(mark);
|
||||
}
|
||||
}
|
||||
|
||||
return check;
|
||||
}
|
||||
|
||||
|
||||
@@ -5196,13 +5196,23 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
|
||||
x.getExpr().accept(this);
|
||||
print(')');
|
||||
|
||||
if (x.getEnable() != null) {
|
||||
if (x.getEnable().booleanValue()) {
|
||||
Boolean enable = x.getEnable();
|
||||
if (enable != null) {
|
||||
if (enable.booleanValue()) {
|
||||
print0(ucase ? " ENABLE" : " enable");
|
||||
} else {
|
||||
print0(ucase ? " DISABLE" : " disable");
|
||||
}
|
||||
}
|
||||
|
||||
Boolean enforced = x.getEnforced();
|
||||
if (enforced != null) {
|
||||
if (enforced.booleanValue()) {
|
||||
print0(ucase ? " ENFORCED" : " enforced");
|
||||
} else {
|
||||
print0(ucase ? " NOT ENFORCED" : " not enforced");
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user