[英]Birt Report - Not gettting data from Postgres RefCursor
I have this: 我有这个:
/*THE PARAMETER in_test_id IS ONLY A TEST!!*/
CREATE OR REPLACE FUNCTION public.test_birt(in_test_id bigint DEFAULT NULL::bigint)
RETURNS refcursor AS
$BODY$
DECLARE
query text;
tcursor refcursor = 'tcursor';
BEGIN
query := 'SELECT * FROM MY_TABLE';
OPEN tcursor FOR execute query;
return tcursor;
END;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
DATASET --> MyDataset --> select * from test_birt(?::bigint)
数据集-> MyDataset->
select * from test_birt(?::bigint)
Here the screenshots: 这里的截图:
Report Design 报告设计
Report Preview 报告预览
I need that Birt shows the values of MY_TABLE !!. 我需要Birt显示MY_TABLE的值! In this case, this table have one varchar field, with the values: TEST1 , TEST2 , TEST3 .
在这种情况下,此表具有一个varchar字段,其值是: TEST1 , TEST2 , TEST3 。 The Birt Version is 3.2 and the postgres is 9.2 .
Birt版本是3.2 ,而postgres是9.2 。
NOTE The unique solution that i found was create a datatype and change the return datatype from my function, something like this: 注意我发现的唯一解决方案是创建一个数据类型并从函数中更改返回数据类型,如下所示:
RETURNS SETOF my_type AS
But I need that Bird can read this RefCursor. 但我需要Bird可以阅读此RefCursor。
You miss a FETCH statement. 您错过了一条FETCH语句。
When you call a function, then cursor "tcursor" is created (and opened). 调用函数时,将创建(并打开)游标“ tcursor”。 But nobody try to read from it.
但是没有人尝试阅读它。 And without explicit support in Birt is impossible to call function and fetch data from cursor.
如果没有Birt的明确支持,就无法调用函数并从游标中获取数据。 You can try a hack - that can work or not (depends on implementation in Birt) - use following commands as source for dataset:
您可以尝试破解-是否有效(取决于Birt中的实现)-使用以下命令作为数据集的来源:
SELECT test_birt(?::bigint); FETCH ALL FROM tcursor;
I found link that shows so Birt didn't support it 5 years ago. 我发现显示的链接使Birt在5年前不支持它。
On second hand. 另一方面。 In 9.2 you don't need to define own types for returning tables.
在9.2中,您不需要为返回表定义自己的类型。 You can use a table types - when you can return all columns or you can define output columns via TABLE keywords:
您可以使用表类型-当您可以返回所有列或可以通过TABLE关键字定义输出列时:
CREATE TABLE foo(a int, b int); -- automatically it defined type foo
CREATE OR REPLACE FUNCTION read_from_foo_1(_a int)
RETURNS SETOF foo AS $$
SELECT * FROM foo WHERE foo.a = _a;
$$ LANGUAGE SQL;
or 要么
CREATE OR REPLACE FUNCTION read_from_foo_2()
RETURNS TABLE(a int, b int, c int) AS $$
SELECT a, b, a + b FROM foo;
$$ LANGUAGE SQL;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.