提交 16bc54a2 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Simplify part of Query.prepareOrder() and fix its javadoc

上级 4c7d0ce4
...@@ -577,14 +577,13 @@ public abstract class Query extends Prepared { ...@@ -577,14 +577,13 @@ public abstract class Query extends Prepared {
/** /**
* Create a {@link SortOrder} object given the list of {@link SelectOrderBy} * Create a {@link SortOrder} object given the list of {@link SelectOrderBy}
* objects. The expression list is extended if necessary. * objects.
* *
* @param orderList a list of {@link SelectOrderBy} elements * @param orderList a list of {@link SelectOrderBy} elements
* @param expressionCount the number of columns in the query * @param expressionCount the number of columns in the query
* @return the {@link SortOrder} object * @return the {@link SortOrder} object
*/ */
public SortOrder prepareOrder(ArrayList<SelectOrderBy> orderList, public SortOrder prepareOrder(ArrayList<SelectOrderBy> orderList, int expressionCount) {
int expressionCount) {
int size = orderList.size(); int size = orderList.size();
int[] index = new int[size]; int[] index = new int[size];
int[] sortType = new int[size]; int[] sortType = new int[size];
...@@ -592,8 +591,7 @@ public abstract class Query extends Prepared { ...@@ -592,8 +591,7 @@ public abstract class Query extends Prepared {
SelectOrderBy o = orderList.get(i); SelectOrderBy o = orderList.get(i);
int idx; int idx;
boolean reverse = false; boolean reverse = false;
Expression expr = o.columnIndexExpr; Value v = o.columnIndexExpr.getValue(null);
Value v = expr.getValue(null);
if (v == ValueNull.INSTANCE) { if (v == ValueNull.INSTANCE) {
// parameter not yet set - order by first column // parameter not yet set - order by first column
idx = 0; idx = 0;
...@@ -612,11 +610,7 @@ public abstract class Query extends Prepared { ...@@ -612,11 +610,7 @@ public abstract class Query extends Prepared {
int type = o.sortType; int type = o.sortType;
if (reverse) { if (reverse) {
// TODO NULLS FIRST / LAST should be inverted too? // TODO NULLS FIRST / LAST should be inverted too?
if ((type & SortOrder.DESCENDING) != 0) { type ^= SortOrder.DESCENDING;
type &= ~SortOrder.DESCENDING;
} else {
type |= SortOrder.DESCENDING;
}
} }
sortType[i] = type; sortType[i] = type;
} }
......
...@@ -289,3 +289,43 @@ SELECT ID FROM TEST FETCH NEXT ROW ONLY LIMIT 1; ...@@ -289,3 +289,43 @@ SELECT ID FROM TEST FETCH NEXT ROW ONLY LIMIT 1;
DROP TABLE TEST; DROP TABLE TEST;
> ok > ok
-- ORDER BY with parameter
CREATE TABLE TEST(A INT, B INT);
> ok
INSERT INTO TEST VALUES (1, 1), (1, 2), (2, 1), (2, 2);
> update count: 4
SELECT * FROM TEST ORDER BY ?, ? FETCH FIRST ROW ONLY;
{
1, 2
> A B
> - -
> 1 1
> rows (ordered): 1
-1, 2
> A B
> - -
> 2 1
> rows (ordered): 1
1, -2
> A B
> - -
> 1 2
> rows (ordered): 1
-1, -2
> A B
> - -
> 2 2
> rows (ordered): 1
2, -1
> A B
> - -
> 2 1
> rows (ordered): 1
}
> update count: 0
DROP TABLE TEST;
> ok
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论