improved sql parser.

This commit is contained in:
wenshao
2017-10-18 15:55:24 +08:00
parent 29a5b5637c
commit 377d9346b8
18 changed files with 705 additions and 84 deletions
@@ -643,6 +643,38 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
SQLExpr left = x.getLeft();
SQLExpr right = x.getRight();
if (inputParameters != null
&& operator != SQLBinaryOperator.Equality) {
int varIndex = -1;
if (right instanceof SQLVariantRefExpr) {
varIndex = ((SQLVariantRefExpr) right).getIndex();
}
Object param = null;
if (varIndex >= 0 && varIndex < inputParameters.size()) {
param = inputParameters.get(varIndex);
}
if (param instanceof Collection) {
Collection values = (Collection) param;
if (values.size() > 0) {
print('(');
int valIndex = 0;
for (Object value : values) {
if (valIndex++ != 0) {
print0(ucase ? " OR " : " or ");
}
printExpr(left);
printOperator(operator);
printParameter(value);
}
print(')');
return false;
}
}
}
if (operator.isRelational()
&& left instanceof SQLIntegerExpr
&& right instanceof SQLIntegerExpr) {
@@ -4604,8 +4636,15 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
@Override
public boolean visit(SQLDeclareItem x) {
SQLDataType dataType = x.getDataType();
if (dataType instanceof SQLRecordDataType) {
print0(ucase ? "TYPE " : "type ");
}
x.getName().accept(this);
if (x.getType() == SQLDeclareItem.Type.TABLE) {
print0(ucase ? " TABLE" : " table");
int size = x.getTableElementList().size();
@@ -4628,9 +4667,14 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
} else if (x.getType() == SQLDeclareItem.Type.CURSOR) {
print0(ucase ? " CURSOR" : " cursor");
} else {
if (x.getDataType() != null) {
print(' ');
x.getDataType().accept(this);
if (dataType != null) {
if (dataType instanceof SQLRecordDataType) {
print0(ucase ? " IS " : " is ");
} else {
print(' ');
}
dataType.accept(this);
}
if (x.getValue() != null) {
if (JdbcConstants.MYSQL.equals(getDbType())) {
@@ -5720,6 +5764,28 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
return false;
}
@Override
public boolean visit(SQLRecordDataType x) {
print0(ucase ? "RECORD (" : "record (");
indentCount++;
println();
List<SQLColumnDefinition> columns = x.getColumns();
for (int i = 0; i < columns.size(); i++) {
if (i != 0) {
println();
}
columns.get(i).accept(this);
if (i != columns.size() - 1) {
print0(", ");
}
}
indentCount--;
println();
print(')');
return false;
}
@Override
public boolean visit(SQLExprStatement x) {
x.getExpr().accept(this);
@@ -793,4 +793,7 @@ public interface SQLASTVisitor {
boolean visit(SQLDropSynonymStatement x);
void endVisit(SQLDropSynonymStatement x);
boolean visit(SQLRecordDataType x);
void endVisit(SQLRecordDataType x);
}
@@ -1846,6 +1846,16 @@ public class SQLASTVisitorAdapter implements SQLASTVisitor {
}
@Override
public boolean visit(SQLRecordDataType x) {
return true;
}
@Override
public void endVisit(SQLRecordDataType x) {
}
public final boolean isEnabled(VisitorFeature feature) {
return VisitorFeature.isEnabled(this.features, feature);
}