小编典典

多个参数值

sql

当我尝试从报表参数传递多个值时,BIRT存在问题。

我正在使用BIRT 2.6.2和Eclipse。

我正在尝试从级联参数组的最后一个参数“ JDSuser”中放入多个值。该参数允许具有多个值,并且我正在使用列表框。

为了能够做到这一点,我正在用where-in语句编写我的sql查询,其中我用javascript替换了文本。否则BIRT
sql无法从report参数获取多个值。

我的SQL查询是

select jamacomment.createdDate, jamacomment.scopeId,
jamacomment.commentText, jamacomment.documentId,
jamacomment.highlightQuote, jamacomment.organizationId,
jamacomment.userId, 
organization.id, organization.name,
userbase.id, userbase.firstName, userbase.lastName,
userbase.organization, userbase.userName,
document.id, document.name, document.description,
user_role.userId, user_role.roleId,
role.id, role.name

from jamacomment jamacomment left join
userbase on userbase.id=jamacomment.userId
left join organization on
organization.id=jamacomment.organizationId
left join document on
document.id=jamacomment.documentId
left join user_role on
user_role.userId=userbase.id
right join role on
role.id=user_role.roleId

where jamacomment.scopeId=11
and role.name in ( 'sample grupa' )
and userbase.userName in ( 'sample' )

而我的JavaScript代码在beforeOpen状态下的数据集是:

if( params["JDSuser"].value[0] != "(All Users)" ){
this.queryText=this.queryText.replaceAll('sample grupa', params["JDSgroup"]);
var users = params["JDSuser"];
//var userquery = "'";
var userquery = userquery + users.join("', '");
//userquery = userquery + "'";
this.queryText=this.queryText.replaceAll('sample', userquery);
}

我尝试了许多不同的报价变体,使用此变体我没有收到错误消息,但是如果我选择1个值,则不会从数据库中获得任何数据,但是如果我选择至少2个值,则将得到最后一个选择的值数据。

如果我取消注释那些其他引号脚本行之一,则将出现如下语法错误:

以下各项有错误:表(id =
597):+处理期间发生异常。有关详细信息,请参见以下消息:无法为数据集准备查询执行:组织无法获取结果集元数据。org.eclipse.birt.report.data.oda.jdbc.JDBCException:SQL语句不返回ResultSet对象。SQL错误#1:您的SQL语法有错误;检查与您的MySQL服务器版本相对应的手册,以在第25行的’rudolfs.sviklis’,’sample’)’附近使用正确的语法;com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:您的SQL语法有错误;检查与您的MySQL服务器版本相对应的手册,以在第25行的’rudolfs.sviklis’,’sample’)’附近使用正确的语法

另外,我应该告诉您,我正在通过工作示例进行了解。一切都一样,前面的代码导致了相同的语法错误,我将其更改为执行相同操作的脚本。该示例位于此处:http :
//developer.actuate.com/community/forum/index.php?/files/file/593-default-
value-all-with-multi-select-
parsmeter/

如果有人至少可以给我提供我应该做什么的线索,那就太好了。


阅读 143

收藏
2021-03-08

共1个答案

小编典典

您应该始终使用参数的value属性,即:

var users = params["JDSuser"].value;

不必在“ userquery”两边加上引号,因为这些引号已放在SQL查询的“样本”中。此外,还有一个错误,因为尚未在以下行定义userquery:

var userquery = userquery + users.join("', '");

这可能会在查询中引入诸如“ null”的字符串。因此,删除对userquery变量的所有引用,只需在末尾使用此表达式即可:

this.queryText=this.queryText.replaceAll('sample', users.join("','"));

注意,我删除了连接表达式中的空格。最后,一旦运行良好,您可能需要通过测试该值是否为null来使报表输入更可靠:

if( params["JDSuser"].value!=null && params["JDSuser"].value[0] != "(All Users)" ){
  //Do stuff...

}
2021-03-08