mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improve sql parser for db2
This commit is contained in:
@@ -23,7 +23,9 @@ import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class DB2SelectQueryBlock extends SQLSelectQueryBlock implements DB2Object {
|
||||
|
||||
private SQLExpr first;
|
||||
private SQLExpr first;
|
||||
|
||||
private Isolation isolation;
|
||||
|
||||
public SQLExpr getFirst() {
|
||||
return first;
|
||||
@@ -54,4 +56,16 @@ public class DB2SelectQueryBlock extends SQLSelectQueryBlock implements DB2Objec
|
||||
}
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
public Isolation getIsolation() {
|
||||
return isolation;
|
||||
}
|
||||
|
||||
public void setIsolation(Isolation isolation) {
|
||||
this.isolation = isolation;
|
||||
}
|
||||
|
||||
public static enum Isolation {
|
||||
RR, RS, CS, UR
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,8 @@ import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLSetQuantifier;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelectQuery;
|
||||
import com.alibaba.druid.sql.dialect.db2.ast.stmt.DB2SelectQueryBlock;
|
||||
import com.alibaba.druid.sql.dialect.db2.ast.stmt.DB2SelectQueryBlock.Isolation;
|
||||
import com.alibaba.druid.sql.parser.ParserException;
|
||||
import com.alibaba.druid.sql.parser.SQLExprParser;
|
||||
import com.alibaba.druid.sql.parser.SQLSelectParser;
|
||||
import com.alibaba.druid.sql.parser.Token;
|
||||
@@ -74,7 +76,7 @@ public class DB2SelectParser extends SQLSelectParser {
|
||||
parseWhere(queryBlock);
|
||||
|
||||
parseGroupBy(queryBlock);
|
||||
|
||||
|
||||
if (lexer.token() == Token.FETCH) {
|
||||
lexer.nextToken();
|
||||
accept(Token.FIRST);
|
||||
@@ -86,6 +88,22 @@ public class DB2SelectParser extends SQLSelectParser {
|
||||
accept(Token.ONLY);
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.WITH) {
|
||||
lexer.nextToken();
|
||||
if (identifierEquals("RR")) {
|
||||
queryBlock.setIsolation(Isolation.RR);
|
||||
} else if (identifierEquals("RS")) {
|
||||
queryBlock.setIsolation(Isolation.RS);
|
||||
} else if (identifierEquals("CS")) {
|
||||
queryBlock.setIsolation(Isolation.CS);
|
||||
} else if (identifierEquals("UR")) {
|
||||
queryBlock.setIsolation(Isolation.UR);
|
||||
} else {
|
||||
throw new ParserException("TODO");
|
||||
}
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
return queryRest(queryBlock);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,12 @@ public class DB2OutputVisitor extends SQLASTOutputVisitor implements DB2ASTVisit
|
||||
print(" ROWS ONLY");
|
||||
}
|
||||
|
||||
if (x.getIsolation() != null) {
|
||||
println();
|
||||
print("WITH ");
|
||||
print(x.getIsolation().name());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user