Search code examples
wso2wso2-enterprise-integratorei

Named parameter can't be used more than one time in a query of Data Service


We are using WXSO2 EI 6.5.0. I prepared Data Service with such simple query:

<sql>SELECT e.code ,e.firstName,e.lastName,e.birthday FROM dbo.elaba_USERS_EMPLOYEES e WHERE e.firstName like :someText  or e.lastName like :someText </sql>
 <param name="someText" paramType="SCALAR" sqlType="STRING"/>

Query produces response

<axis2ns1092:DataServiceFault xmlns:axis2ns1092="http://ws.wso2.org/dataservice">
    <axis2ns1092:current_params>{someText=Gar6va}</axis2ns1092:current_params>
    <axis2ns1092:source_data_service>
        <axis2ns1092:data_service_name>ElabaDataTest</axis2ns1092:data_service_name>
        <axis2ns1092:description>N/A</axis2ns1092:description>
        <axis2ns1092:location>/ElabaDataTest.dbs</axis2ns1092:location>
        <axis2ns1092:default_namespace>http://ws.wso2.org/dataservice</axis2ns1092:default_namespace>
    </axis2ns1092:source_data_service>
    <axis2ns1092:ds_code>DATABASE_ERROR</axis2ns1092:ds_code>
    <axis2ns1092:nested_exception>java.lang.NullPointerException</axis2ns1092:nested_exception>
    <axis2ns1092:current_request_name>_get_users_employeestest</axis2ns1092:current_request_name>
</axis2ns1092:DataServiceFault>

If I delete one criteria with parameter :some Text, query works properly. Such queries worked in WSO DSS 3.5.1 without problems.


Solution

  • After some investigation I found a mistake in class org.wso2.carbon.dataservices.core.description.query.ExpressionQuery. There is a method processDynamicQuery and code

    if (tmpParam != null && !(tempParams.get(i).isOptional()) && DBConstants.DataTypes.QUERY_STRING.equals(tmpParam.getSqlType())) {
    

    is not correct.

    ...tempParams.get(i).isOptional()
    

    throws null pointer exception.

    It would be very nice to find fixed code.