提交 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>
......
......@@ -150,7 +150,7 @@ import org.h2.value.ValueTimestamp;
/**
* The parser is used to convert a SQL statement string to an command object.
*
*
* @author Thomas Mueller
* @author Noel Grandin
* @author Nicolas Fortin, Atelier SIG, IRSTV FR CNRS 24888
......@@ -211,7 +211,7 @@ public class Parser {
/**
* Parse the statement and prepare it for execution.
*
*
* @param sql the SQL statement to parse
* @return the prepared object
*/
......@@ -226,7 +226,7 @@ public class Parser {
/**
* Parse a statement or a list of statements, and prepare it for execution.
*
*
* @param sql the SQL statement to parse
* @return the command object
*/
......@@ -259,7 +259,7 @@ public class Parser {
/**
* Parse the statement, but don't prepare it for execution.
*
*
* @param sql the SQL statement to parse
* @return the prepared object
*/
......@@ -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 (readIf("WITH")) {
read("RS");
}
}
if (database.getMode().isolationLevelInSelectStatement) {
parseIsolationClause();
}
}
/**
* DB2 isolation clause
*/
private void parseIsolationClause() {
if (readIf("WITH")) {
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")) {
}
}
}
......@@ -3518,7 +3534,7 @@ public class Parser {
/**
* Checks if this string is a SQL keyword.
*
*
* @param s the token to check
* @param supportOffsetFetch if OFFSET and FETCH are keywords
* @return true if it is a keyword
......@@ -5623,7 +5639,7 @@ public class Parser {
/**
* Add double quotes around an identifier if required.
*
*
* @param s the identifier
* @return the quoted identifier
*/
......@@ -5654,7 +5670,7 @@ public class Parser {
/**
* Parse a SQL code snippet that represents an expression.
*
*
* @param sql the code snippet
* @return the expression object
*/
......@@ -5667,7 +5683,7 @@ public class Parser {
/**
* Parse a SQL code snippet that represents a table name.
*
*
* @param sql the code snippet
* @return the table object
*/
......
......@@ -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");
......@@ -191,7 +196,7 @@ public class Mode {
/**
* Get the mode with the given name.
*
*
* @param name the name of the mode
* @return the mode object
*/
......
......@@ -25,7 +25,7 @@ public class TestCompatibility extends TestBase {
/**
* Run just this test.
*
*
* @param a ignored
*/
public static void main(String... a) throws Exception {
......@@ -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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论