提交 9e3dfffa authored 作者: noelgrandin's avatar noelgrandin

Fix Issue 406: support "SELECT h2version()"

上级 6c21d32d
......@@ -3837,6 +3837,14 @@ Returns the name of the current user of this session.
CURRENT_USER()
"
"Functions (System)","H2VERSION","
H2VERSION()
","
Returns the H2 version as a String.
","
H2VERSION()
"
"System Tables","Information Schema","
INFORMATION_SCHEMA
","
......
......@@ -27,6 +27,7 @@ Change Log
</li><li>Add new collation command SET BINARY_COLLATION UNSIGNED, helps with people testing BINARY columns in MySQL mode.
</li><li>Fix issue #453, ABBA race conditions in TABLE LINK connection sharing.
</li><li>Fix Issue 449: Postgres Serial data type should not automatically be marked as primary key
</li><li>Fix Issue 406: support "SELECT h2version()"
</li></ul>
<h2>Version 1.3.171 (2013-03-17)</h2>
......
......@@ -26,6 +26,7 @@ import java.util.regex.PatternSyntaxException;
import org.h2.command.Command;
import org.h2.command.Parser;
import org.h2.constant.ErrorCode;
import org.h2.engine.Constants;
import org.h2.engine.Database;
import org.h2.engine.Mode;
import org.h2.engine.Session;
......@@ -101,6 +102,12 @@ public class Function extends Expression implements FunctionCall {
LINK_SCHEMA = 218, GREATEST = 219, LEAST = 220, CANCEL_SESSION = 221, SET = 222, TABLE = 223, TABLE_DISTINCT = 224,
FILE_READ = 225, TRANSACTION_ID = 226, TRUNCATE_VALUE = 227, NVL2 = 228, DECODE = 229, ARRAY_CONTAINS = 230;
/**
* This is called H2VERSION() and not VERSION(), because we return a fake value
* for VERSION() when running under the PostgreSQL ODBC driver.
*/
public static final int H2VERSION = 231;
public static final int ROW_NUMBER = 300;
private static final int VAR_ARGS = -1;
......@@ -346,6 +353,7 @@ public class Function extends Expression implements FunctionCall {
addFunctionNotDeterministic("TRANSACTION_ID", TRANSACTION_ID, 0, Value.STRING);
addFunctionWithNull("DECODE", DECODE, VAR_ARGS, Value.NULL);
addFunctionNotDeterministic("DISK_SPACE_USED", DISK_SPACE_USED, 1, Value.LONG);
addFunction("H2VERSION", H2VERSION, 0, Value.STRING);
// TableFunction
addFunctionWithNull("TABLE", TABLE, VAR_ARGS, Value.RESULT_SET);
......@@ -1138,6 +1146,9 @@ public class Function extends Expression implements FunctionCall {
case LPAD:
result = ValueString.get(StringUtils.pad(v0.getString(), v1.getInt(), v2 == null ? null : v2.getString(), false));
break;
case H2VERSION:
result = ValueString.get(Constants.getVersion());
break;
case DATE_ADD:
result = ValueTimestamp.get(dateadd(v0.getString(), v1.getInt(), v2.getTimestamp()));
break;
......
......@@ -31,6 +31,7 @@ import java.util.Properties;
import java.util.UUID;
import org.h2.api.AggregateFunction;
import org.h2.constant.ErrorCode;
import org.h2.engine.Constants;
import org.h2.store.fs.FileUtils;
import org.h2.test.TestBase;
import org.h2.tools.SimpleResultSet;
......@@ -56,6 +57,7 @@ public class TestFunctions extends TestBase implements AggregateFunction {
public void test() throws Exception {
deleteDb("functions");
testVersion();
testFunctionTable();
testArrayParameters();
testDefaultConnection();
......@@ -82,6 +84,20 @@ public class TestFunctions extends TestBase implements AggregateFunction {
FileUtils.deleteRecursive(TEMP_DIR, true);
}
private void testVersion() throws SQLException {
Connection conn = getConnection("functions");
Statement stat = conn.createStatement();
String query = "select h2version()";
ResultSet rs = stat.executeQuery(query);
assertTrue(rs.next());
String version = rs.getString(1);
assertEquals(Constants.getVersion(), version);
assertFalse(rs.next());
rs.close();
stat.close();
conn.close();
}
private void testFunctionTable() throws SQLException {
Connection conn = getConnection("functions");
Statement stat = conn.createStatement();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论