imporoved sql parser.

This commit is contained in:
wenshao
2017-10-15 03:13:30 +08:00
parent 0527591d6a
commit 7da600e088
117 changed files with 9172 additions and 491 deletions
@@ -2225,6 +2225,17 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
return false;
}
public boolean visit(SQLDropEventStatement x) {
print0(ucase ? "DROP EVENT " : "drop event ");
if (x.isIfExists()) {
print0(ucase ? "IF EXISTS " : "if exists ");
}
printExpr(x.getName());
return false;
}
public boolean visit(SQLColumnDefinition x) {
boolean parameterized = this.parameterized;
this.parameterized = false;
@@ -3011,6 +3022,38 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
print0(ucase ? " ON " : " on ");
table.accept(this);
}
SQLExpr algorithm = x.getAlgorithm();
if (algorithm != null) {
print0(ucase ? " ALGORITHM " : " algorithm ");
algorithm.accept(this);
}
SQLExpr lockOption = x.getLockOption();
if (lockOption != null) {
print0(ucase ? " LOCK " : " lock ");
lockOption.accept(this);
}
return false;
}
@Override
public boolean visit(SQLDropLogFileGroupStatement x) {
print0(ucase ? "DROP LOGFILE GROUP " : "drop logfile group ");
x.getName().accept(this);
return false;
}
@Override
public boolean visit(SQLDropServerStatement x) {
print0(ucase ? "DROP SERVER " : "drop server ");
if (x.isIfExists()) {
print0(ucase ? "IF EXISTS " : "if exists ");
}
x.getName().accept(this);
return false;
}
@@ -3069,6 +3112,78 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
return false;
}
@Override
public boolean visit(SQLAlterViewStatement x) {
print0(ucase ? "ALTER " : "atler ");
this.indentCount++;
String algorithm = x.getAlgorithm();
if (algorithm != null && algorithm.length() > 0) {
print0(ucase ? "ALGORITHM = " : "algorithm = ");
print0(algorithm);
println();
}
SQLName definer = x.getDefiner();
if (definer != null) {
print0(ucase ? "DEFINER = " : "definer = ");
definer.accept(this);
println();
}
String sqlSecurity = x.getSqlSecurity();
if (sqlSecurity != null && sqlSecurity.length() > 0) {
print0(ucase ? "SQL SECURITY = " : "sql security = ");
print0(sqlSecurity);
println();
}
this.indentCount--;
print0(ucase ? "VIEW " : "view ");
if (x.isIfNotExists()) {
print0(ucase ? "IF NOT EXISTS " : "if not exists ");
}
x.getTableSource().accept(this);
if (x.getColumns().size() > 0) {
print0(" (");
this.indentCount++;
println();
for (int i = 0; i < x.getColumns().size(); ++i) {
if (i != 0) {
print0(", ");
println();
}
x.getColumns().get(i).accept(this);
}
this.indentCount--;
println();
print(')');
}
if (x.getComment() != null) {
println();
print0(ucase ? "COMMENT " : "comment ");
x.getComment().accept(this);
}
println();
print0(ucase ? "AS" : "as");
println();
x.getSubQuery().accept(this);
if (x.isWithCheckOption()) {
println();
print0(ucase ? "WITH CHECK OPTION" : "with check option");
}
return false;
}
@Override
public boolean visit(SQLCreateViewStatement x) {
print0(ucase ? "CREATE " : "create ");
@@ -3475,6 +3590,12 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
print0(x.getUsing());
}
SQLExpr comment = x.getComment();
if (comment != null) {
print0(ucase ? " COMMENT " : " comment ");
comment.accept(this);
}
return false;
}
@@ -3525,6 +3646,23 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
print0(" (");
printAndAccept(x.getColumns(), ", ");
print(')');
SQLForeignKeyImpl.Match match = x.getReferenceMatch();
if (match != null) {
print0(ucase ? " MATCH " : " match ");
print0(ucase ? match.name : match.name_lcase);
}
if (x.getOnDelete() != null) {
print0(ucase ? " ON DELETE " : " on delete ");
print0(ucase ? x.getOnDelete().name : x.getOnDelete().name_lcase);
}
if (x.getOnUpdate() != null) {
print0(ucase ? " ON UPDATE " : " on update ");
print0(ucase ? x.getOnUpdate().name : x.getOnUpdate().name_lcase);
}
return false;
}
@@ -3759,6 +3897,12 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
x.getName().accept(this);
SQLExpr engine = x.getEngine();
if (engine != null) {
print0(ucase ? " ENGINE " : " engine ");
engine.accept(this);
}
return false;
}
@@ -3816,6 +3960,12 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
print0(ucase ? " USING " : " using ");
print0(x.getUsing());
}
SQLExpr comment = x.getComment();
if (comment != null) {
print0(ucase ? " COMMENT " : " comment ");
printExpr(comment);
}
return false;
}
@@ -4751,6 +4901,12 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
if (x.isUpgradeDataDirectoryName()) {
print0(ucase ? " UPGRADE DATA DIRECTORY NAME" : " upgrade data directory name");
}
SQLAlterCharacter character = x.getCharacter();
if (character != null) {
print(' ');
character.accept(this);
}
return false;
}
@@ -5483,4 +5639,23 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
print0(ucase ? "SHOW ERRORS" : "show errors");
return true;
}
@Override
public boolean visit(SQLAlterCharacter x) {
print0(ucase ? "CHARACTER SET = " : "character set = ");
x.getCharacterSet().accept(this);
if (x.getCollate() != null) {
print0(ucase ? ", COLLATE = " : ", collate = ");
x.getCollate().accept(this);
}
return false;
}
@Override
public boolean visit(SQLExprStatement x) {
x.getExpr().accept(this);
return false;
}
}
@@ -769,4 +769,25 @@ public interface SQLASTVisitor {
boolean visit(SQLShowErrorsStatement x);
void endVisit(SQLShowErrorsStatement x);
boolean visit(SQLAlterCharacter x);
void endVisit(SQLAlterCharacter x);
boolean visit(SQLExprStatement x);
void endVisit(SQLExprStatement x);
boolean visit(SQLAlterProcedureStatement x);
void endVisit(SQLAlterProcedureStatement x);
boolean visit(SQLAlterViewStatement x);
void endVisit(SQLAlterViewStatement x);
boolean visit(SQLDropEventStatement x);
void endVisit(SQLDropEventStatement x);
boolean visit(SQLDropLogFileGroupStatement x);
void endVisit(SQLDropLogFileGroupStatement x);
boolean visit(SQLDropServerStatement x);
void endVisit(SQLDropServerStatement x);
}
@@ -315,6 +315,13 @@ public class SQLASTVisitorAdapter implements SQLASTVisitor {
public void endVisit(SQLCreateViewStatement x) {
}
public boolean visit(SQLAlterViewStatement x) {
return true;
}
public void endVisit(SQLAlterViewStatement x) {
}
public boolean visit(SQLCreateViewStatement.Column x) {
return true;
}
@@ -1769,6 +1776,66 @@ public class SQLASTVisitorAdapter implements SQLASTVisitor {
}
@Override
public boolean visit(SQLAlterCharacter x) {
return true;
}
@Override
public void endVisit(SQLAlterCharacter x) {
}
@Override
public boolean visit(SQLExprStatement x) {
return true;
}
@Override
public void endVisit(SQLExprStatement x) {
}
@Override
public boolean visit(SQLAlterProcedureStatement x) {
return true;
}
@Override
public void endVisit(SQLAlterProcedureStatement x) {
}
@Override
public boolean visit(SQLDropEventStatement x) {
return true;
}
@Override
public void endVisit(SQLDropEventStatement x) {
}
@Override
public boolean visit(SQLDropLogFileGroupStatement x) {
return true;
}
@Override
public void endVisit(SQLDropLogFileGroupStatement x) {
}
@Override
public boolean visit(SQLDropServerStatement x) {
return true;
}
@Override
public void endVisit(SQLDropServerStatement x) {
}
public final boolean isEnabled(VisitorFeature feature) {
return VisitorFeature.isEnabled(this.features, feature);
}
@@ -538,7 +538,7 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
handleRelationship(left, x.getOperator().name, right);
break;
case BooleanOr:{
case BooleanOr: {
List<SQLExpr> list = SQLBinaryOpExpr.split(x, op);
for (SQLExpr item : list) {
@@ -551,6 +551,15 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
return false;
}
case Modulus:
if (right instanceof SQLIdentifierExpr) {
long hashCode64 = ((SQLIdentifierExpr) right).hashCode64();
if (hashCode64 == FnvHash.Constants.ISOPEN) {
left.accept(this);
return false;
}
}
break;
default:
break;
}
@@ -1834,6 +1843,16 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
return false;
}
public boolean visit(SQLAlterViewStatement x) {
if (repository != null
&& x.getParent() == null) {
repository.resolve(x);
}
x.getSubQuery().accept(this);
return false;
}
@Override
public boolean visit(SQLAlterTableDropForeignKey x) {
return false;
@@ -2376,4 +2395,17 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
public boolean visit(SQLAlterTypeStatement x) {
return false;
}
public boolean visit(SQLAlterProcedureStatement x) {
return false;
}
public boolean visit(SQLExprStatement x) {
SQLExpr expr = x.getExpr();
if (expr instanceof SQLName) {
return false;
}
return true;
}
}