2 Replies Latest reply: Oct 17, 2011 12:49 PM by 758447 RSS

    How to use a list of strings as a data service parameter

    758447
      Hello.

      I need to build a service that receives a list of string as parameter. I read the thread List of values as param - is it possible to push down the query? but I was unable to make it work.

      In my namespace, I defined an element:

      <xs:element name="keyList">
      <xs:simpleType>
      <xs:list itemType='xs:string'/>
      </xs:simpleType>
      </xs:element>

      In my dataservice, I declared the following function:

      declare function tns:list($keyList as element(bt:keyList)) as element(bt:employee)* {

      for $key in $keyList
      for $employee in emp:EMPLOYEES()
      where (fn:upper-case($employee/STR_KEY) eq fn:upper-case(fn:string($key)))
      return
      <bt:employee>
      <bt:name>{fn:data($employee/STR_NAME)}</bt:name>
      </bt:employee>
      };

      When I test this, the generated SQL considers all the keys as the only parameter:
      (...)
      WHERE (UPPER(t1."STR_NAME") = ?)
      (...)

      So, if I try a one-string list, it works:
      (...)
      WHERE (UPPER(t1."STR_NAME") = 'STRING1')
      (...)

      But with two ou more strings...
      (...)
      WHERE (UPPER(t1."STR_NAME") = 'STRING1 STRING2')
      (...)

      What I am doing wrong?

      Also, about the thread I mentioned, I would like to know how could I make the reference "for $paramString in $paramStrings/AN_ELEMENT" using my code.

      Kind regards, and thank you for your time!