提交 605ca8ec authored 作者: Thomas Mueller's avatar Thomas Mueller

User defined functions with source code didn't work after re-opening the database.

上级 ac5370da
...@@ -23,6 +23,7 @@ import org.h2.util.ClassUtils; ...@@ -23,6 +23,7 @@ import org.h2.util.ClassUtils;
import org.h2.util.ObjectArray; import org.h2.util.ObjectArray;
import org.h2.util.SourceCompiler; import org.h2.util.SourceCompiler;
import org.h2.util.StatementBuilder; import org.h2.util.StatementBuilder;
import org.h2.util.StringUtils;
import org.h2.value.DataType; import org.h2.value.DataType;
import org.h2.value.Value; import org.h2.value.Value;
import org.h2.value.ValueNull; import org.h2.value.ValueNull;
...@@ -185,7 +186,11 @@ public class FunctionAlias extends DbObjectBase { ...@@ -185,7 +186,11 @@ public class FunctionAlias extends DbObjectBase {
if (deterministic) { if (deterministic) {
buff.append(" DETERMINISTIC"); buff.append(" DETERMINISTIC");
} }
if (source != null) {
buff.append(" AS ").append(StringUtils.quoteStringSQL(source));
} else {
buff.append(" FOR ").append(Parser.quoteIdentifier(className + "." + methodName)); buff.append(" FOR ").append(Parser.quoteIdentifier(className + "." + methodName));
}
return buff.toString(); return buff.toString();
} }
...@@ -412,4 +417,8 @@ public class FunctionAlias extends DbObjectBase { ...@@ -412,4 +417,8 @@ public class FunctionAlias extends DbObjectBase {
return deterministic; return deterministic;
} }
public String getSource() {
return source;
}
} }
...@@ -65,10 +65,18 @@ public class TestFunctions extends TestBase implements AggregateFunction { ...@@ -65,10 +65,18 @@ public class TestFunctions extends TestBase implements AggregateFunction {
Connection conn = getConnection("functions"); Connection conn = getConnection("functions");
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
ResultSet rs; ResultSet rs;
stat.execute("create force alias sayHi as 'String test(String name) { return \"Hello \" + name; }'"); stat.execute("create force alias sayHi as 'String test(String name) {\nreturn \"Hello \" + name;\n}'");
rs = stat.executeQuery("call sayHi('Joe')"); rs = stat.executeQuery("call sayHi('Joe')");
rs.next(); rs.next();
assertEquals("Hello Joe", rs.getString(1)); assertEquals("Hello Joe", rs.getString(1));
if (!config.memory) {
conn.close();
conn = getConnection("functions");
stat = conn.createStatement();
rs = stat.executeQuery("call sayHi('Joe')");
rs.next();
assertEquals("Hello Joe", rs.getString(1));
}
stat.execute("drop alias sayHi"); stat.execute("drop alias sayHi");
conn.close(); conn.close();
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论