当脚本允许多个值时,如何在脚本中检查我的参数是否为null?

时间:2018-03-30 16:05:51

标签: sql parameters null birt

我在级联参数中创建了非必需参数: enter image description here

不需要month-opt参数并且允许多个值。

我在查询中使用了这个参数,所以我创建了一个脚本:

if(params["MONTH-OPT"].value != null && params["MONTH-OPT"].value != ""){
    this.queryText = this.queryText + " AND MONTH IN (" + params["MONTH-OPT"].value.join("," ) +") ";
}

我的问题是:如果用户选择空值:

enter image description here

然后,我遇到了一个问题:

Cannot get the result set metadata.
    org.eclipse.birt.report.data.oda.jdbc.JDBCException: SQL statement does not return a ResultSet object.
SQL error #1:Incorrect syntax near ')'.
 ;
    java.sql.SQLException: Incorrect syntax near ')'. (Element ID:18061) 

似乎关于null的测试不正确,因为它绕过了检查。如果我不允许多个值,它正在工作......

2 个答案:

答案 0 :(得分:0)

当您使用IN运算符时,需要在括号中始终有一些值。

 INVALID SYNTAX 
 select * from table where id in ()


 Valid Syntax 
   select * from table where id in (null)
   or 
   select * from table where id in ('') 

等 在代码中进行更改以传递空值以解决问题。

您可以在脚本中使用简单的if条件

if  params["MONTH-OPT"].value =  Null
   select * from table
else 
  select * from table where id in (1, 2)  etc 

答案 1 :(得分:0)

基于:https://fr.scribd.com/document/15350321/BIRT-Multi-Value-Cascading-Parameters

修复可以(我认为它不是最好的......):

if(params["MONTH-OPT"].value != null ){
    var monthOptionNullValue = params["MONTH-OPT"].toString();
    if( monthOptionNullValue != null && monthOptionNullValue != ""){
        this.queryText = this.queryText + " AND MONTH IN (" + params["MONTH-OPT"].value.join("," ) +") ";
    }
}

感谢srp的帮助