提交 65d5f5e7 authored 作者: noelgrandin's avatar noelgrandin

Add support for DB2 "WITH UR" clause, patch from litailang

上级 b19ef746
...@@ -41,6 +41,7 @@ See also <a href="build.html#providing_patches">Providing Patches</a>. ...@@ -41,6 +41,7 @@ See also <a href="build.html#providing_patches">Providing Patches</a>.
</li><li>Remove support for the old-style outer join syntax using "(+)" because it is buggy. </li><li>Remove support for the old-style outer join syntax using "(+)" because it is buggy.
</li><li>Change license to MPL 2.0. </li><li>Change license to MPL 2.0.
</li><li>Not allow relative database URLs like jdbc:h2:test; instead, require using jdbc:h2:./test. </li><li>Not allow relative database URLs like jdbc:h2:test; instead, require using jdbc:h2:./test.
</li><li>Add support for DB2 "WITH UR" clause, patch from litailang
</li></ul> </li></ul>
<h2>Priority 1</h2> <h2>Priority 1</h2>
......
...@@ -1012,7 +1012,7 @@ public class Parser { ...@@ -1012,7 +1012,7 @@ public class Parser {
} }
if (readIf("DEFAULT")) { if (readIf("DEFAULT")) {
read("VALUES"); read("VALUES");
Expression[] expr = { }; Expression[] expr = {};
command.addRow(expr); command.addRow(expr);
} else if (readIf("VALUES")) { } else if (readIf("VALUES")) {
read("("); read("(");
...@@ -1745,16 +1745,32 @@ public class Parser { ...@@ -1745,16 +1745,32 @@ public class Parser {
} while (readIf(",")); } while (readIf(","));
} else if (readIf("NOWAIT")) { } else if (readIf("NOWAIT")) {
// TODO parser: select for update nowait: should not wait // TODO parser: select for update nowait: should not wait
} else if (readIf("WITH")) {
// Hibernate / Derby support
read("RR");
} }
command.setForUpdate(true); command.setForUpdate(true);
} else if (readIf("READ") || readIf("FETCH")) { } else if (readIf("READ") || readIf("FETCH")) {
read("ONLY"); read("ONLY");
}
}
if (database.getMode().isolationLevelInSelectStatement) {
parseIsolationClause();
}
}
/**
* DB2 isolation clause
*/
private void parseIsolationClause() {
if (readIf("WITH")) { if (readIf("WITH")) {
read("RS"); if (readIf("RR") || readIf("RS")) {
// concurrent-access-resolution clause
if (readIf("USE")) {
read("AND");
read("KEEP");
if (readIf("SHARE") || readIf("UPDATE") || readIf("EXCLUSIVE")) {
}
read("LOCKS");
} }
} else if (readIf("CS") || readIf("UR")) {
} }
} }
} }
......
...@@ -123,6 +123,10 @@ public class Mode { ...@@ -123,6 +123,10 @@ public class Mode {
*/ */
public boolean swapConvertFunctionParameters; public boolean swapConvertFunctionParameters;
/**
* can set the isolation level using WITH {RR|RS|CS|UR}
*/
public boolean isolationLevelInSelectStatement;
private final String name; private final String name;
...@@ -135,6 +139,7 @@ public class Mode { ...@@ -135,6 +139,7 @@ public class Mode {
mode.aliasColumnName = true; mode.aliasColumnName = true;
mode.supportOffsetFetch = true; mode.supportOffsetFetch = true;
mode.sysDummy1 = true; mode.sysDummy1 = true;
mode.isolationLevelInSelectStatement = true;
add(mode); add(mode);
mode = new Mode("Derby"); mode = new Mode("Derby");
......
...@@ -374,6 +374,23 @@ public class TestCompatibility extends TestBase { ...@@ -374,6 +374,23 @@ public class TestCompatibility extends TestBase {
res.next(); res.next();
assertEquals("2", res.getString(1)); assertEquals("2", res.getString(1));
assertFalse(res.next()); assertFalse(res.next());
// test isolation-clause
conn = getConnection("compatibility;MODE=DB2");
stat = conn.createStatement();
stat.execute("drop table test if exists");
stat.execute("create table test(id varchar)");
res = stat.executeQuery("select * from test where id = 1 with rr");
res = stat.executeQuery("select * from test order by id fetch next 2 rows only with rr");
res = stat.executeQuery("select * from test order by id fetch next 2 rows only with rs");
res = stat.executeQuery("select * from test order by id fetch next 2 rows only with cs");
res = stat.executeQuery("select * from test order by id fetch next 2 rows only with ur");
// test isolation-clause with lock-request-clause
res = stat
.executeQuery("select * from test order by id fetch next 2 rows only with rr use and keep share locks");
res = stat
.executeQuery("select * from test order by id fetch next 2 rows only with rs use and keep update locks");
res = stat
.executeQuery("select * from test order by id fetch next 2 rows only with rr use and keep exclusive locks");
} }
private void testDerby() throws SQLException { private void testDerby() throws SQLException {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论