提交 effa19c7 authored 作者: Thomas Mueller's avatar Thomas Mueller

DB2 compatibility: the DB2 fetch-first-clause is supported.

上级 4148226f
......@@ -1354,33 +1354,34 @@ public class Parser {
command.setOrder(orderList);
currentSelect = oldSelect;
}
int test;
// if (database.getMode().supportOffsetFetch) {
// if (readIf("OFFSET")) {
// Select temp = currentSelect;
// // make sure aggregate functions will not work here
// currentSelect = null;
// command.setOffset(readExpression().optimize(session));
// if (!readIf("ROW")) {
// read("ROWS");
// }
// currentSelect = temp;
// }
// if (readIf("FETCH")) {
// Select temp = currentSelect;
// // make sure aggregate functions will not work here
// currentSelect = null;
// if (readIf("FIRST")) {
// Expression limit = readExpression().optimize(session);
// command.setLimit(limit);
// if (!readIf("ROW")) {
// read("ROWS");
// }
// readIf("ONLY");
// }
// currentSelect = temp;
// }
// }
if (database.getMode().supportOffsetFetch) {
// make sure aggregate functions will not work here
Select temp = currentSelect;
currentSelect = null;
// http://sqlpro.developpez.com/SQL2008/
if (readIf("OFFSET")) {
command.setOffset(readExpression().optimize(session));
if (!readIf("ROW")) {
read("ROWS");
}
}
if (readIf("FETCH")) {
read("FIRST");
if (readIf("ROW")) {
command.setLimit(ValueExpression.get(ValueInt.get(1)));
} else {
Expression limit = readExpression().optimize(session);
command.setLimit(limit);
if (!readIf("ROW")) {
read("ROWS");
}
}
read("ONLY");
}
currentSelect = temp;
}
if (readIf("LIMIT")) {
Select temp = currentSelect;
// make sure aggregate functions will not work here
......
......@@ -132,6 +132,7 @@ public class Mode {
add(mode);
mode = new Mode("DB2");
mode.supportOffsetFetch = true;
add(mode);
}
......
SET MODE DB2;
SELECT * FROM SYSTEM_RANGE(1, 100) OFFSET 99 ROWS;
> 100;
SELECT * FROM SYSTEM_RANGE(1, 100) OFFSET 50 ROWS FETCH FIRST 1 ROW ONLY;
> 51;
SELECT * FROM SYSTEM_RANGE(1, 100) FETCH FIRST 1 ROWS ONLY;
> 1;
SELECT * FROM SYSTEM_RANGE(1, 100) FETCH FIRST ROW ONLY;
> 1;
SET MODE REGULAR;
CREATE TABLE Address (id NUMBER NOT NULL, city VARCHAR2(255), PRIMARY KEY (id));
CREATE TABLE Person (id NUMBER NOT NULL, name VARCHAR2(255), ADDRESS_ID NUMBER, PRIMARY KEY (id));
INSERT INTO PERSON (id, name) values (1, 'Frank');
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论