提交 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>.
</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>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>
<h2>Priority 1</h2>
......
......@@ -1012,7 +1012,7 @@ public class Parser {
}
if (readIf("DEFAULT")) {
read("VALUES");
Expression[] expr = { };
Expression[] expr = {};
command.addRow(expr);
} else if (readIf("VALUES")) {
read("(");
......@@ -1745,16 +1745,32 @@ public class Parser {
} while (readIf(","));
} else if (readIf("NOWAIT")) {
// TODO parser: select for update nowait: should not wait
} else if (readIf("WITH")) {
// Hibernate / Derby support
read("RR");
}
command.setForUpdate(true);
} else if (readIf("READ") || readIf("FETCH")) {
read("ONLY");
}
}
if (database.getMode().isolationLevelInSelectStatement) {
parseIsolationClause();
}
}
/**
* DB2 isolation clause
*/
private void parseIsolationClause() {
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 {
*/
public boolean swapConvertFunctionParameters;
/**
* can set the isolation level using WITH {RR|RS|CS|UR}
*/
public boolean isolationLevelInSelectStatement;
private final String name;
......@@ -135,6 +139,7 @@ public class Mode {
mode.aliasColumnName = true;
mode.supportOffsetFetch = true;
mode.sysDummy1 = true;
mode.isolationLevelInSelectStatement = true;
add(mode);
mode = new Mode("Derby");
......
......@@ -374,6 +374,23 @@ public class TestCompatibility extends TestBase {
res.next();
assertEquals("2", res.getString(1));
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 {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论