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

dynamic parameters example

上级 14ab748f
...@@ -48,6 +48,7 @@ public class TestFunctions extends TestBase implements AggregateFunction { ...@@ -48,6 +48,7 @@ public class TestFunctions extends TestBase implements AggregateFunction {
public void test() throws Exception { public void test() throws Exception {
deleteDb("functions"); deleteDb("functions");
testDynamicArgumentAndReturn();
testUUID(); testUUID();
testDeterministic(); testDeterministic();
testTransactionId(); testTransactionId();
...@@ -59,6 +60,20 @@ public class TestFunctions extends TestBase implements AggregateFunction { ...@@ -59,6 +60,20 @@ public class TestFunctions extends TestBase implements AggregateFunction {
deleteDb("functions"); deleteDb("functions");
} }
private void testDynamicArgumentAndReturn() throws SQLException {
Connection conn = getConnection("functions");
Statement stat = conn.createStatement();
ResultSet rs;
stat.execute("create alias dynamic deterministic for \"" + getClass().getName() + ".dynamic\"");
setCount(0);
rs = stat.executeQuery("call dynamic(('a', 1))[0]");
rs.next();
String a = rs.getString(1);
assertEquals("a1", a);
stat.execute("drop alias dynamic");
conn.close();
}
private void testUUID() throws SQLException { private void testUUID() throws SQLException {
Connection conn = getConnection("functions"); Connection conn = getConnection("functions");
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
...@@ -656,6 +671,20 @@ public class TestFunctions extends TestBase implements AggregateFunction { ...@@ -656,6 +671,20 @@ public class TestFunctions extends TestBase implements AggregateFunction {
a.getLeastSignificantBits() ^ b.getLeastSignificantBits()); a.getLeastSignificantBits() ^ b.getLeastSignificantBits());
} }
/**
* This method is called via reflection from the database.
*
* @param args the argument list
* @return an array of one element
*/
public static Object[] dynamic(Object[] args) {
StringBuilder buff = new StringBuilder();
for (Object a : args) {
buff.append(a);
}
return new Object[] { buff.toString() };
}
public void add(Object value) { public void add(Object value) {
// ignore // ignore
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论