Using input parameter as an optional input

99封情书 提交于 2019-12-14 02:17:25

问题


Using wso2, DSS version 3.01, I am trying to have an input parameter that could be an optional parameter. A user can say, give me all the info for this specific code, or if a user does not specify any code, I want to give all the rows of data. Can you help?


回答1:


Instead of creating a query for each optional parameter, you can also do the following:

<query id="selectEmployees" useConfig="default">
   <sql>select * from Employees where (:employeeNumber is null or employeeNumber = :employeeNumber)</sql>
   <result element="employees" rowName="employee">
      <element column="lastName" name="last-name" xsdType="string"/>
      <element column="firstName" name="first-name" xsdType="string"/>
      <element column="email" name="email" xsdType="string"/>
      <element column="salary" name="salary" xsdType="double"/>
   </result>
   <param defaultValue="#{NULL}" name="employeeNumber" ordinal="1" paramType="SCALAR" sqlType="INTEGER" type="IN"/>
</query>
<operation name="getEmployees">
   <call-query href="selectEmployees">
      <with-param name="employeeNumber" query-param="employeeNumber"/>
   </call-query>
</operation>

Now you can call 'getEmployees' with 'employeeNumber' and get specific employee,
or you can call 'getEmployees' without 'employeeNumber' and get all employees.
(Calling without 'employeeNumber' is by omitting the 'employeeNumber' tag, or using 'xsi:nil="true"'.)
Obviously, you cannot query for the value 'null' this way.




回答2:


ok soo for example

<query id="employeesByNumberSQL" useConfig="default">
  <sql>select * from Employees where employeeNumber = ?</sql>
  <result element="employees" rowName="employee">
     <element column="lastName" name="last-name" xsdType="string"/>
     <element column="firstName" name="first-name" xsdType="string"/>
     <element column="email" name="email" xsdType="string"/>
     <element column="salary" name="salary" xsdType="double"/>
  </result>
  <param name="employeeNumber" ordinal="1" paramType="SCALAR" sqlType="INTEGER" type="IN"/>

select * from Employees

You have two queries employeesByNumberSQL, employeesByNumberSQL1 these two are mapped togetemployeesByNumber and getemployeesByNumber2




回答3:


Well you can make input parameters optional by giving default values to the input parameters. For example

<query id="MyQ" useConfig="myDS">
  <sql>select cust_id,name from customer where cust_id = ?</sql>
  <result element="Entries" rowName="Entry">
     <element column="cust_id" name="cust_id" xsdType="string"/>
     <element column="name" name="name" xsdType="string"/>
  </result>
  <param defaultValue="1" name="cust_id" sqlType="INTEGER"/>
</query>

Here if you do not mention the input parameters it will take the input parameter as one. Or else you need to create two queries and handle them programmatically



来源:https://stackoverflow.com/questions/19326683/using-input-parameter-as-an-optional-input

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!