如何创建一个接受多个 (CSV) 值的 BIRT 数据集,这些值可以在“IN"中使用?select语句中的子句 [英] How to create a BIRT dataset that accepts multiple (CSV) values that it can be used inside "IN" clause in select statement

查看:35
本文介绍了如何创建一个接受多个 (CSV) 值的 BIRT 数据集,这些值可以在“IN"中使用?select语句中的子句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 BIRT 报告中创建一个数据集,该数据集包含一个带有IN"子句的选择语句,并传递一个逗号分隔值代替?"使用接受多个值的 BIRT 参数.

I am trying to create a dataset in BIRT report that contains a select statement with "IN" clause and pass a comma separate value in place of "?" using a BIRT parameter that accepts multiple values.

例如:select * from table where ID in (?)

for eg : select * from table where ID in ( ? )

我尝试在我的数据集select * from table where ID in (params["paramer_name"].value)"中添加它,但它不起作用.

I tried adding this in my dataset "select * from table where ID in ( params["paramer_name"].value)" but it is not working.

我不想使用 BIRT 数据集的内置过滤器,因为在查询中使用IN"子句可以在很大程度上降低我的数据库服务器中的查询成本.

I do not want to use the built in Filter of BIRT dataset because using the "IN" clause in query reduces the cost of query to lot of extent in my database server.

是否有一种简单的方法可以在不添加长 Java 脚本的情况下执行相同操作???

Is there a simple way to do the same without adding long java scripts ???

仅供参考:用户选择的参数列表来自另一个数据集,我想使用所选值作为另一个数据集的输入.

FYI : The list of parameter that user selects comes from another dataset, and I want to use the selected value as an input to another dataset.

非常感谢您的帮助...

Thanks a lot for your help...

推荐答案

我们不能用常规的 SQL 参数?"来做到这一点.

We cannot do this with a regular SQL parameter '?'.

一种解决方法是替换这个?"通过查询中的默认值,并在数据集的beforeOpen"脚本中动态注入适当的逗号分隔值列表:

A workaround is to replace this '?' by a default value in the query, and dynamically inject an appropriate comma-separated list of values in the "beforeOpen" script of the dataset:

默认查询

假设ID的数据类型是整数,这样设置查询(当然这里使用有效的ID可以预览数据):

Assuming the datatype of ID is an integer, set up the query like this (of course use here a valid ID to be able to preview data):

select * from table where ID in ( 1000 )

数据集的beforeOpen"脚本:

   this.queryText=this.queryText.replaceAll('1000',params["parameter_name"].value.join(","));

这样,如果parameter_name"返回 3 个值 1100,1200,1300,发送到数据库的查询将是:

This way, if "parameter_name" returns 3 values 1100,1200,1300 the query sent to the database will be:

select * from table where ID in ( 1100,1200,1300)

如果ID的数据类型是String也类似,我们只需要稍微加引号.但是对于 String 类型,这种处理使得 SQL 注入攻击成为可能,我们应该首先检查参数值是否与我们期望的一样.

It is similar if the datatype of ID is a String, we just have to play a little bit with quotes. However with a String type this kind of handling makes SQL Injection attacks possible, we should firstly check if parameter values look like what we expect.

这篇关于如何创建一个接受多个 (CSV) 值的 BIRT 数据集,这些值可以在“IN"中使用?select语句中的子句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆