[#1020] Improve Oracle's LIMIT .. OFFSET clause simulation. GitHub Issue

#16 - Fixed generated syntax error and bad variable binding
This commit is contained in:
Lukas Eder 2012-05-25 10:02:14 +02:00
parent 38592d92c8
commit 5c6638bd5c
2 changed files with 21 additions and 27 deletions

View File

@ -393,40 +393,31 @@ implements
toSQLReference0(local);
String enclosed = local.render();
String innerSubqueryName = "inner_" + Util.hash(enclosed);
String outerSubqueryName = "outer_" + Util.hash(enclosed);
String subqueryName = "limit_" + Util.hash(enclosed);
String rownumName = "rownum_" + Util.hash(enclosed);
context.keyword("select * from (")
.formatIndentStart()
.formatNewLine()
.keyword("select ")
.sql(outerSubqueryName)
.keyword(".*, rownum as ")
.sql(rownumName)
.formatSeparator()
.keyword("from (")
.formatIndentStart()
.formatNewLine()
.keyword("select ")
.sql(innerSubqueryName)
.keyword(".*")
.formatSeparator()
.keyword("from (")
.formatIndentStart()
.formatNewLine()
.sql(enclosed)
.keyword("select ")
.sql(subqueryName)
.keyword(".*, rownum as ")
.sql(rownumName)
.formatSeparator()
.keyword("from (")
.formatIndentStart()
.formatNewLine()
.sql(enclosed)
.formatIndentEnd()
.formatNewLine()
.sql(") ")
.sql(subqueryName)
.formatSeparator()
.keyword("where rownum <= ")
.sql(getLimit().getUpperRownum())
.formatIndentEnd()
.formatNewLine()
.sql(") ")
.sql(innerSubqueryName)
.formatSeparator()
.keyword("where rownum <=")
.sql(getLimit().getUpperRownum())
.sql(outerSubqueryName)
.formatIndentEnd()
.formatNewLine()
.keyword(")")
.formatSeparator()
.keyword("where ")
.sql(rownumName)

View File

@ -277,8 +277,11 @@ class Limit extends AbstractQueryPart {
// Oracle knows no LIMIT or TOP clause, limits are always bound
// ------------------------------------------------------------
case ORACLE: {
context.bind(getLowerRownum());
// [#1020] With the ROWNUM filtering improvement, the upper
// limit is bound before the lower limit
context.bind(getUpperRownum());
context.bind(getLowerRownum());
break;
}
}