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