提交 61f2493e authored 作者: noelgrandin's avatar noelgrandin

Support "SELECT version()"

Patch from Andrew Gaul argaul@gmail.com
Fixes issue 406.
上级 9d53c2d0
...@@ -3811,6 +3811,14 @@ Returns the name of the current user of this session. ...@@ -3811,6 +3811,14 @@ Returns the name of the current user of this session.
CURRENT_USER() CURRENT_USER()
" "
"Functions (System)","VERSION","
VERSION()
","
Returns the H2 version as a String.
","
VERSION()
"
"System Tables","Information Schema"," "System Tables","Information Schema","
INFORMATION_SCHEMA INFORMATION_SCHEMA
"," ","
......
...@@ -25,6 +25,7 @@ Change Log ...@@ -25,6 +25,7 @@ Change Log
</li><li>MVStore: old data is now retained for 45 seconds by default. </li><li>MVStore: old data is now retained for 45 seconds by default.
</ul><li>MVStore: compress is now disabled by default, and can be enabled on request. </ul><li>MVStore: compress is now disabled by default, and can be enabled on request.
</ul><li>Support ALTER TABLE ADD ... AFTER. Patch from Andrew Gaul argaul@gmail.com. Fixes issue 401. </ul><li>Support ALTER TABLE ADD ... AFTER. Patch from Andrew Gaul argaul@gmail.com. Fixes issue 401.
</ul><li>support "SELECT version()". Patch from Andrew Gaul argaul@gmail.com. Fixes issue 406.
</li></ul> </li></ul>
<h2>Version 1.3.170 (2012-11-30)</h2> <h2>Version 1.3.170 (2012-11-30)</h2>
......
...@@ -26,6 +26,7 @@ import java.util.regex.PatternSyntaxException; ...@@ -26,6 +26,7 @@ import java.util.regex.PatternSyntaxException;
import org.h2.command.Command; import org.h2.command.Command;
import org.h2.command.Parser; import org.h2.command.Parser;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
import org.h2.engine.Constants;
import org.h2.engine.Database; import org.h2.engine.Database;
import org.h2.engine.Mode; import org.h2.engine.Mode;
import org.h2.engine.Session; import org.h2.engine.Session;
...@@ -97,7 +98,8 @@ public class Function extends Expression implements FunctionCall { ...@@ -97,7 +98,8 @@ public class Function extends Expression implements FunctionCall {
CASE = 206, NEXTVAL = 207, CURRVAL = 208, ARRAY_GET = 209, CSVREAD = 210, CSVWRITE = 211, 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, 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, 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; FILE_READ = 225, TRANSACTION_ID = 226, TRUNCATE_VALUE = 227, NVL2 = 228, DECODE = 229, ARRAY_CONTAINS = 230,
VERSION = 231;
public static final int ROW_NUMBER = 300; public static final int ROW_NUMBER = 300;
...@@ -343,6 +345,7 @@ public class Function extends Expression implements FunctionCall { ...@@ -343,6 +345,7 @@ public class Function extends Expression implements FunctionCall {
addFunction("FILE_READ", FILE_READ, VAR_ARGS, Value.NULL, false, false, false); addFunction("FILE_READ", FILE_READ, VAR_ARGS, Value.NULL, false, false, false);
addFunctionNotDeterministic("TRANSACTION_ID", TRANSACTION_ID, 0, Value.STRING); addFunctionNotDeterministic("TRANSACTION_ID", TRANSACTION_ID, 0, Value.STRING);
addFunctionWithNull("DECODE", DECODE, VAR_ARGS, Value.NULL); addFunctionWithNull("DECODE", DECODE, VAR_ARGS, Value.NULL);
addFunction("VERSION", VERSION, 0, Value.STRING);
// TableFunction // TableFunction
addFunctionWithNull("TABLE", TABLE, VAR_ARGS, Value.RESULT_SET); addFunctionWithNull("TABLE", TABLE, VAR_ARGS, Value.RESULT_SET);
...@@ -1114,6 +1117,9 @@ public class Function extends Expression implements FunctionCall { ...@@ -1114,6 +1117,9 @@ public class Function extends Expression implements FunctionCall {
case LPAD: case LPAD:
result = ValueString.get(StringUtils.pad(v0.getString(), v1.getInt(), v2 == null ? null : v2.getString(), false)); result = ValueString.get(StringUtils.pad(v0.getString(), v1.getInt(), v2 == null ? null : v2.getString(), false));
break; break;
case VERSION:
result = ValueString.get(Constants.getVersion());
break;
// date // date
case DATE_ADD: case DATE_ADD:
result = ValueTimestamp.get(dateadd(v0.getString(), v1.getInt(), v2.getTimestamp())); result = ValueTimestamp.get(dateadd(v0.getString(), v1.getInt(), v2.getTimestamp()));
......
...@@ -29,6 +29,7 @@ import java.util.Properties; ...@@ -29,6 +29,7 @@ import java.util.Properties;
import java.util.UUID; import java.util.UUID;
import org.h2.api.AggregateFunction; import org.h2.api.AggregateFunction;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
import org.h2.engine.Constants;
import org.h2.store.fs.FileUtils; import org.h2.store.fs.FileUtils;
import org.h2.test.TestBase; import org.h2.test.TestBase;
import org.h2.tools.SimpleResultSet; import org.h2.tools.SimpleResultSet;
...@@ -54,6 +55,7 @@ public class TestFunctions extends TestBase implements AggregateFunction { ...@@ -54,6 +55,7 @@ public class TestFunctions extends TestBase implements AggregateFunction {
public void test() throws Exception { public void test() throws Exception {
deleteDb("functions"); deleteDb("functions");
testVersion();
testFunctionTable(); testFunctionTable();
testArrayParameters(); testArrayParameters();
testDefaultConnection(); testDefaultConnection();
...@@ -79,6 +81,20 @@ public class TestFunctions extends TestBase implements AggregateFunction { ...@@ -79,6 +81,20 @@ public class TestFunctions extends TestBase implements AggregateFunction {
FileUtils.deleteRecursive(TEMP_DIR, true); FileUtils.deleteRecursive(TEMP_DIR, true);
} }
private void testVersion() throws SQLException {
Connection conn = getConnection("functions");
Statement stat = conn.createStatement();
String query = "select version()";
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 { private void testFunctionTable() throws SQLException {
Connection conn = getConnection("functions"); Connection conn = getConnection("functions");
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论