mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improved oracle sql parser support fetch clause. issue #1448
This commit is contained in:
@@ -23,7 +23,7 @@ import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class DB2SelectQueryBlock extends SQLSelectQueryBlock implements DB2Object {
|
||||
|
||||
private SQLExpr first;
|
||||
|
||||
|
||||
private Isolation isolation;
|
||||
|
||||
@@ -31,14 +31,6 @@ public class DB2SelectQueryBlock extends SQLSelectQueryBlock implements DB2Objec
|
||||
|
||||
private SQLExpr optimizeFor;
|
||||
|
||||
public SQLExpr getFirst() {
|
||||
return first;
|
||||
}
|
||||
|
||||
public void setFirst(SQLExpr first) {
|
||||
this.first = first;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
if (visitor instanceof DB2ASTVisitor) {
|
||||
|
||||
@@ -38,27 +38,6 @@ public class DB2OutputVisitor extends SQLASTOutputVisitor implements DB2ASTVisit
|
||||
public boolean visit(DB2SelectQueryBlock x) {
|
||||
this.visit((SQLSelectQueryBlock) x);
|
||||
|
||||
if (x.getFirst() != null) {
|
||||
|
||||
//order by 语句必须在FETCH FIRST ROWS ONLY之前
|
||||
SQLObject parent= x.getParent();
|
||||
if(parent instanceof SQLSelect)
|
||||
{
|
||||
SQLOrderBy orderBy= ((SQLSelect) parent).getOrderBy();
|
||||
if (orderBy!=null&&orderBy.getItems().size() > 0) {
|
||||
println();
|
||||
print0(ucase ? "ORDER BY " : "order by ");
|
||||
printAndAccept(orderBy.getItems(), ", ");
|
||||
((SQLSelect) parent).setOrderBy(null);
|
||||
}
|
||||
}
|
||||
println();
|
||||
print0(ucase ? "FETCH FIRST " : "fetch first ");
|
||||
x.getFirst().accept(this);
|
||||
print0(ucase ? " ROWS ONLY" : " rows only");
|
||||
|
||||
|
||||
}
|
||||
if (x.isForReadOnly()) {
|
||||
println();
|
||||
print0(ucase ? "FOR READ ONLY" : "for read only");
|
||||
|
||||
@@ -109,6 +109,8 @@ public class OracleLexer extends Lexer {
|
||||
map.put("PURGE", Token.PURGE);
|
||||
map.put("INITIALLY", Token.INITIALLY);
|
||||
|
||||
map.put("FETCH", Token.FETCH);
|
||||
|
||||
DEFAULT_ORACLE_KEYWORDS = new Keywords(map);
|
||||
}
|
||||
|
||||
|
||||
@@ -276,6 +276,8 @@ public class OracleSelectParser extends SQLSelectParser {
|
||||
|
||||
parseModelClause(queryBlock);
|
||||
|
||||
parseFetchClause(queryBlock);
|
||||
|
||||
return queryRest(queryBlock);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,12 +17,7 @@ package com.alibaba.druid.sql.dialect.oracle.visitor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLHint;
|
||||
import com.alibaba.druid.sql.ast.SQLObject;
|
||||
import com.alibaba.druid.sql.ast.SQLParameter;
|
||||
import com.alibaba.druid.sql.ast.SQLSetQuantifier;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.ast.*;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLAllColumnExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLCharExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
|
||||
@@ -572,6 +567,8 @@ public class OracleOutputVisitor extends SQLASTOutputVisitor implements OracleAS
|
||||
x.getModelClause().accept(this);
|
||||
}
|
||||
|
||||
printFetchFirst(x);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user