多个参数值

时间:2014-09-09 13:19:30

标签: sql eclipse birt

当我尝试从报告参数传递多个值时,我遇到了BIRT问题。

我正在使用BIRT 2.6.2和eclipse。

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

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

我的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' )

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

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对应的手册   服务器版本,在'rudolfs.sviklis'附近使用正确的语法,   第25行的“样本”)       com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:您的SQL语法中有错误;检查对应的手册   您的MySQL服务器版本,以便在附近使用正确的语法   'rudolfs.sviklis','样本')'在第25行

另外,我应该告诉你,我是通过从工作示例来看这样做的。一切都是一样的,前面的代码导致了相同的语法错误,我把它改成了这个脚本也做了同样的事情。 这个例子可以在这里找到: http://developer.actuate.com/community/forum/index.php?/files/file/593-default-value-all-with-multi-select-parsmeter/

如果有人能给我至少一个我应该做的事情的线索,那就太棒了。

1 个答案:

答案 0 :(得分:3)

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

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

没有必要包围" userquery"引号,因为这些引号已经放在SQL查询arround' sample'中。此外,还有一个错误,因为尚未在第一行定义userquery:

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

这可能会引入一个字符串,如#34; null"在您的查询中。因此,删除对userquery变量的所有引用,只需在结尾处使用此表达式:

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

注意我删除了连接表达式中的空白区域。最后,一旦它工作正常,您可能需要通过测试值是否为null来使报表输入更加健壮:

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

}