improved oracle sql parser support fetch clause. issue #1448

This commit is contained in:
wenshao
2016-10-14 17:48:10 +08:00
parent 27e6b8f9f4
commit 4f612ec2e0
9 changed files with 139 additions and 36 deletions
@@ -787,9 +787,31 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
x.getOrderBy().accept(this);
}
printFetchFirst(x);
return false;
}
protected void printFetchFirst(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");
}
}
public boolean visit(SQLSelectItem x) {
if (x.isConnectByRoot()) {
print0(ucase ? "CONNECT_BY_ROOT " : "connect_by_root ");