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

When creating functions within a schema, those functions could not be used in…

When creating functions within a schema, those functions could not be used in views, nested queries, and constraints.
上级 502a8dbd
......@@ -7,6 +7,8 @@
package org.h2.expression;
import org.h2.command.Parser;
import org.h2.constant.SysProperties;
import org.h2.engine.Constants;
import org.h2.engine.FunctionAlias;
import org.h2.engine.Session;
import org.h2.table.ColumnResolver;
......@@ -81,6 +83,11 @@ public class JavaFunction extends Expression implements FunctionCall {
public String getSQL() {
StatementBuilder buff = new StatementBuilder();
// TODO always append the schema once FUNCTIONS_IN_SCHEMA is enabled
if (SysProperties.FUNCTIONS_IN_SCHEMA ||
!functionAlias.getSchema().equals(Constants.SCHEMA_MAIN)) {
buff.append(Parser.quoteIdentifier(functionAlias.getSchema().getName())).append('.');
}
buff.append(Parser.quoteIdentifier(functionAlias.getName())).append('(');
for (Expression e : args) {
buff.appendExceptFirst(", ");
......
......@@ -48,6 +48,7 @@ public class TestFunctions extends TestBase implements AggregateFunction {
public void test() throws Exception {
deleteDb("functions");
testFunctionInSchema();
testGreatest();
testSource();
testDynamicArgumentAndReturn();
......@@ -64,6 +65,24 @@ public class TestFunctions extends TestBase implements AggregateFunction {
deleteDb("functions");
FileSystem.getInstance(TEMP_DIR).deleteRecursive(TEMP_DIR, true);
}
private void testFunctionInSchema() throws SQLException {
Connection conn = getConnection("functions");
Statement stat = conn.createStatement();
stat.execute("create schema schema2");
stat.execute("create alias schema2.func as 'int x() { return 1; }'");
stat.execute("create view test as select schema2.func()");
ResultSet rs;
rs = stat.executeQuery("select * from information_schema.views");
rs.next();
assertTrue(rs.getString("VIEW_DEFINITION").indexOf("SCHEMA2.FUNC") >= 0);
stat.execute("drop view test");
stat.execute("drop schema schema2");
conn.close();
}
private void testGreatest() throws SQLException {
Connection conn = getConnection("functions");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论