mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improved mysql 8.16 support, sql parser support check not enforced option, fix #4082
This commit is contained in:
@@ -23,6 +23,7 @@ import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
public class SQLCheck extends SQLConstraintImpl implements SQLTableElement, SQLTableConstraint, SQLReplaceable {
|
||||
|
||||
private SQLExpr expr;
|
||||
private Boolean enforced;
|
||||
|
||||
public SQLCheck(){
|
||||
|
||||
@@ -63,6 +64,8 @@ public class SQLCheck extends SQLConstraintImpl implements SQLTableElement, SQLT
|
||||
if (expr != null) {
|
||||
expr = expr.clone();
|
||||
}
|
||||
|
||||
x.enforced = enforced;
|
||||
}
|
||||
|
||||
public SQLCheck clone() {
|
||||
@@ -89,4 +92,12 @@ public class SQLCheck extends SQLConstraintImpl implements SQLTableElement, SQLT
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public Boolean getEnforced() {
|
||||
return enforced;
|
||||
}
|
||||
|
||||
public void setEnforced(Boolean enforced) {
|
||||
this.enforced = enforced;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1549,6 +1549,22 @@ public class MySqlCreateTableParser extends SQLCreateTableParser {
|
||||
SQLExpr expr = this.exprParser.expr();
|
||||
check.setExpr(expr);
|
||||
constraint = check;
|
||||
|
||||
if (lexer.token() == Token.HINT) {
|
||||
String hintText = lexer.stringVal();
|
||||
if (hintText != null) {
|
||||
hintText = hintText.trim();
|
||||
}
|
||||
|
||||
if (hintText.startsWith("!")) {
|
||||
if (hintText.endsWith("NOT ENFORCED")) {
|
||||
check.setEnforced(false);
|
||||
} else if (hintText.endsWith(" ENFORCED")) {
|
||||
check.setEnforced(true);
|
||||
}
|
||||
lexer.nextToken();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (constraint != null) {
|
||||
|
||||
@@ -5273,6 +5273,16 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
|
||||
x.getExpr().accept(this);
|
||||
this.indentCount--;
|
||||
print(')');
|
||||
|
||||
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