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

New system function TRANSACTION_ID().

上级 aa89ddc7
......@@ -100,7 +100,7 @@ public class Function extends Expression implements FunctionCall {
CASE = 206, NEXTVAL = 207, CURRVAL = 208, ARRAY_GET = 209, CSVREAD = 210, CSVWRITE = 211,
MEMORY_FREE = 212, MEMORY_USED = 213, LOCK_MODE = 214, SCHEMA = 215, SESSION_ID = 216, ARRAY_LENGTH = 217,
LINK_SCHEMA = 218, GREATEST = 219, LEAST = 220, CANCEL_SESSION = 221, SET = 222, TABLE = 223, TABLE_DISTINCT = 224,
FILE_READ = 225;
FILE_READ = 225, TRANSACTION_ID = 226;
private static final int VAR_ARGS = -1;
......@@ -318,6 +318,7 @@ public class Function extends Expression implements FunctionCall {
addFunction("CANCEL_SESSION", CANCEL_SESSION, 1, Value.BOOLEAN);
addFunction("SET", SET, 2, Value.NULL, false, false);
addFunction("FILE_READ", FILE_READ, VAR_ARGS, Value.NULL, false, true);
addFunctionNotConst("TRANSACTION_ID", TRANSACTION_ID, 0, Value.STRING);
// TableFunction
addFunctionWithNull("TABLE", TABLE, VAR_ARGS, Value.RESULT_SET);
......@@ -817,6 +818,10 @@ public class Function extends Expression implements FunctionCall {
result = ValueBoolean.get(cancelStatement(session, v0.getInt()));
break;
}
case TRANSACTION_ID: {
result = session.getTransactionId();
break;
}
default:
result = null;
}
......
......@@ -44,6 +44,7 @@ public class TestFunctions extends TestBase implements AggregateFunction {
public void test() throws Exception {
deleteDb("functions");
testTransactionId();
testPrecision();
testVarArgs();
testAggregate();
......@@ -52,6 +53,30 @@ public class TestFunctions extends TestBase implements AggregateFunction {
deleteDb("functions");
}
private void testTransactionId() throws SQLException {
if (config.memory) {
return;
}
Connection conn = getConnection("functions");
Statement stat = conn.createStatement();
stat.execute("create table test(id int)");
ResultSet rs;
rs = stat.executeQuery("call transaction_id()");
rs.next();
assertTrue(rs.getString(1) == null && rs.wasNull());
stat.execute("insert into test values(1)");
rs = stat.executeQuery("call transaction_id()");
rs.next();
assertTrue(rs.getString(1) == null && rs.wasNull());
conn.setAutoCommit(false);
stat.execute("delete from test");
rs = stat.executeQuery("call transaction_id()");
rs.next();
assertTrue(rs.getString(1) != null);
stat.execute("drop table test");
conn.close();
}
private void testPrecision() throws SQLException {
Connection conn = getConnection("functions");
Statement stat = conn.createStatement();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论