外部化 BIRT 查询

发布于 2024-08-24 15:29:31 字数 92 浏览 3 评论 0原文

有没有办法外部化 BIRT 报告的报告查询。我们需要支持多个数据库引擎,因此我们的查询根据底层数据库的不同而不同。我想使用配置参数来告诉 BIRT 报告使用特定的查询文件

Is there a way to externalize report queries for BIRT reports. We need to support multiple database engines and so our queries are different depending on the underlying database. I would like to use a config parameter to tell BIRT report to use a specific query file

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

耳钉梦 2024-08-31 15:29:31

当然可以。如果您在报告本身中编写一些 JavaScript,它可以访问磁盘上的文件以检索文本查询在执行之前修改查询。

您需要为其编码的事件是数据源上的 beforeOpen。实际上,我们通过检测通配符参数是否设置为 "*" 并动态调整 SQL 查询,将其从: 更改

select A from B where C = ?

为:

select A from B where ((C = ?) or (1==1))

丑陋的修改只是为了让我们不必担心改变位置参数。

您可以从磁盘文件中读取一行并使用以下内容更改查询:

try {
  var fip0 = new Packages.java.io.FileInputStream("/query.txt");
  try {
    var fip1 = new Packages.java.io.DataInputStream(fip0);
    try {
      queryText = fip1.readLine() + "";
    } catch(e1) {}
    fip1.close();
  } catch(e2) {}
  fip0.close();
} catch(e3) {}

尽管您可能应该有比这更好的错误检查:-)我删除了它,因为它(1)有点大; (2) 具有一定的专有性。

Sure you can. If you code up some Javascript in the report itself, it can access files on the disk to retrieve the textual queries and modify the query before it's executed.

The event you need to code for is beforeOpen on the data source. We actually use this for wildcarding parameters by detecting if they're set to "*" and dynamically adjusting the SQL query, changing it from:

select A from B where C = ?

to:

select A from B where ((C = ?) or (1==1))

The ugly modification is just so we don't have to worry about changing the positional parameters.

You can read a line from a disk file and change the query with something like:

try {
  var fip0 = new Packages.java.io.FileInputStream("/query.txt");
  try {
    var fip1 = new Packages.java.io.DataInputStream(fip0);
    try {
      queryText = fip1.readLine() + "";
    } catch(e1) {}
    fip1.close();
  } catch(e2) {}
  fip0.close();
} catch(e3) {}

although you should probably have better error checking than that :-) I removed it as it's (1) somewhat large; and (2) somewhat proprietary.

小…楫夜泊 2024-08-31 15:29:31

我不知道有什么方法可以开箱即用地做到这一点。您可能会想象一些相当复杂的脚本来在数据集的 onLoad 事件上触发。

在每个数据库中放置相同的存储过程怎么样?然后,您可以参数化数据连接信息(在报表数据源的编辑页面上)并动态指示报表查询特定数据源。只要存储过程位于所有实例上,您就可以从正确的源获取正确的数据。

I do not know of a way to do this out of the box. You could probably dream up some fairly complex scripting to fire off on the onLoad event of the Data Set.

How about placing the same stored procedure in each DB? THen you can parameterize the data connection information (On the Edit page for the report Data Source) and dynamically direct your report to query a specific data source. As long as the stored proc is on all instances, you will get the correct data from the correct source.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文