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

Improved compatibility for "fetch first / next row(s)". Thanks a lot to litailang for the patch!

上级 b6ad6d6a
...@@ -1606,7 +1606,9 @@ public class Parser { ...@@ -1606,7 +1606,9 @@ public class Parser {
} }
} }
if (readIf("FETCH")) { if (readIf("FETCH")) {
read("FIRST"); if (!readIf("FIRST")) {
read("NEXT");
}
if (readIf("ROW")) { if (readIf("ROW")) {
command.setLimit(ValueExpression.get(ValueInt.get(1))); command.setLimit(ValueExpression.get(ValueInt.get(1)));
} else { } else {
......
...@@ -130,6 +130,7 @@ public class Mode { ...@@ -130,6 +130,7 @@ public class Mode {
mode = new Mode("Derby"); mode = new Mode("Derby");
mode.aliasColumnName = true; mode.aliasColumnName = true;
mode.uniqueIndexSingleNull = true; mode.uniqueIndexSingleNull = true;
mode.supportOffsetFetch = true;
mode.sysDummy1 = true; mode.sysDummy1 = true;
add(mode); add(mode);
...@@ -164,6 +165,7 @@ public class Mode { ...@@ -164,6 +165,7 @@ public class Mode {
mode.aliasColumnName = true; mode.aliasColumnName = true;
mode.nullConcatIsNull = true; mode.nullConcatIsNull = true;
mode.roundWhenConvertToLong = true; mode.roundWhenConvertToLong = true;
mode.supportOffsetFetch = true;
mode.systemColumns = true; mode.systemColumns = true;
add(mode); add(mode);
} }
......
...@@ -243,12 +243,23 @@ public class TestCompatibility extends TestBase { ...@@ -243,12 +243,23 @@ public class TestCompatibility extends TestBase {
assertThrows(ErrorCode.SCHEMA_NOT_FOUND_1, conn.createStatement()). assertThrows(ErrorCode.SCHEMA_NOT_FOUND_1, conn.createStatement()).
executeQuery("SELECT 1 FROM sysibm.sysdummy1"); executeQuery("SELECT 1 FROM sysibm.sysdummy1");
conn.close(); conn.close();
conn = getConnection("compatibility;MODE=DB2");
Statement stmt = conn.createStatement();
stmt.execute("drop table test");
stmt.execute("create table test(id varchar)");
stmt.execute("insert into test values ('3'),('1'),('2')");
res = stmt.executeQuery("select id from test order by id fetch next 2 rows only");
conn = getConnection("compatibility"); conn = getConnection("compatibility");
res.next();
assertEquals("1", res.getString(1));
res.next();
assertEquals("2", res.getString(1));
assertFalse(res.next());
} }
private void testDerby() throws SQLException { private void testDerby() throws SQLException {
conn = getConnection("compatibility;MODE=Derby"); conn = getConnection("compatibility;MODE=Derby");
ResultSet res = conn.createStatement().executeQuery("SELECT 1 FROM sysibm.sysdummy1"); ResultSet res = conn.createStatement().executeQuery("SELECT 1 FROM sysibm.sysdummy1 fetch next 1 row only");
res.next(); res.next();
assertEquals("1", res.getString(1)); assertEquals("1", res.getString(1));
conn.close(); conn.close();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论