The query in a data service specifies the type of task that should be performed on the data in a particular data store. For example, consider the task of retrieving data from a data store, or posting, updating, and deleting data. Data consumers send requests to the data service by invoking the relevant operation (or REST resource) in the data service. Consequently, the query connected to the operation/resource is executed to perform the task.
REST resources and Operations are used depending on whether the particular task should be invoked RESTfully, or by using SOAP. Read more about REST resources and operations in data services.
If the data store supports SQL, you need to specify the SQL statement to execute the required task.
select EmployeeNumber, FirstName, LastName, Email from Employees where EmployeeNumber=:EmployeeNumber
Input mappings allow you to add parameters to a query so that you can set the parameter value when executing the query.
For example, if you are writing an SQL query that requires an input value, you need to specify the parameters that can be used to provide the input. Consider an SQL statement for getting details of an employee from a data store. To get the details, it is necessary to provide the identifier of the employee in the data store.
|Generate Input Mapping
|If you have defined an SQL query, you can generate input mappings corresponding to the input fields specified in the query by clicking Generate Input Mappings.
|Returning Generated Keys
It inserts data to a table that has auto increment key columns. The auto incremented key value of the record is mapped to the result output mappings of the data service. For example, the sample query below is used to insert values to a table by the name of
wes_teams , which has an auto increment column:
INSERT INTO wes_teams(TEAM) VALUES(?)
Once the user selects
Return Generated Keys , an auto increment key is added as an output mapping.
|Returning Updated Key Count
|With the current data services functionality, we don't have a way to indicate that the update operation did not affect any rows. But we can return the updated row count as a response to the client in update/insert queries to indicate how may rows are affected by the query execution.
For each input, you can specify the following parameter values:
This is the data type of the input mapping, which determines how the input mapping parameter will be given in the target query.
Note that ARRAY parameter type cannot be used with the QUERY_STRING data type (SQL type).
In the context of RDBMS and SQL datasources, an ARRAY parameter mapped to an SQL query will be expanded to multiple comma separated parameters at runtime. For example, this can be used in SQL statement conditions such as SELECT ... WHERE ... IN(?).
|The data type of the corresponding SQL parameter can be selected from this menu. Note that the QUERY_STRING data type cannot be used if the parameter type is set to ARRAY. Read more about data types.
Default values help you automatically assign a value to a parameter when a user has not entered a specific parameter value in a request. Therefore, this value gets automatically added to the query if it is ignored by the user.
You can refer to internal property values using default values. You can use special system variables that are defined as default values. At the moment, it only provides a variable for retrieving the username of the current user authenticated in a secured data service. You can access this variable as follows:
|These are used in stored procedures. IN is the usual parameter we give to provide some value. OUT only returns a value from a stored procedure. INOUT does both.
|See input validators
Just as Input mapping allows you to add parameters to a query, output mapping determines how the output of a query should be presented. Use this section to specify how the result of the query should be presented. You can choose XML, JSON, or RDF as the format of the result, along with the parameters that should be used to represent the data.
|The output type determines the format in which the query output will be presented. You can select either XML, RDF, or JSON.
|Use Column Numbers
|If this option is selected, the mapping will be done by the column number basis instead of the column name.
|Escape Non Printable Characters
|Use this option if the data in your database consists of characters that are not serializable to XML. Few examples are " '. When you invoke services that access such data and produce responses, the sever throws errors. This option ensures that non-printable characters will be ignored when producing the responses.
The following parameters are configurable for XML/RDF output types.
|Generate Output Mapping
Note that this option is only available for
If you have defined an SQL query, you can generate output mappings corresponding to the fields specified in the query by clicking Generate Response. In the example shown below, there is an SQL query that needs to output values for the
|See Defining Namespaces .
For each output element, you can specify the following parameters:
|Select the mapping type.
|Output Field Name
|The name for the output field.
|Select the datasource type.
This is the data type of the output element.
|Give name for the export. The result element can be declared to be exported with a given name when defining a query in a data service. The query request export feature must be used in conjunction with request box. It allows individual queries executed in a request to communicate with each other. The concept is 'exporting' a specific result element so that the next calling query will get that result element as a query parameter. Therefore, if you have two queries (namely 'query1' and 'query2') that is executed sequentially in a request box, and if 'query1' has a specific result element and if that element is exported with the name 'foo', then 'query2' also gets a query param named 'foo'. Therefore, when this request box session is executed, the query1's exported value will be passed into query2 as an input parameter. This feature is very useful in situations where the result of an earlier-executed query is required for the execution of a subsequent query (e.g. a newly created primay key).
There are two export types that can be used.
Advanced query parameters¶
Advanced query properties help define additional features when querying an RDBMS. Query property details are described below.
Sets a timeout for the underlying JDBC query.
The number of rows that should be fetched from the database when more rows are needed. If the fetch size is zero, the JDBC driver ignores the value and is free to make its own best guess as to what the fetch size should be. Note that the fetch size is set to a lower value in the Micro Integrator by default. However, if you expect a very large number of rows to be fetched, you should increase the fetch size accordingly (e.g. 1000) to improve performance.
Max Field Size
Maximum data size for the field.
Maximum number of rows to be returned. Zero means all rows.
Force Stored Procedure
Forces the current SQl statement as a stored procedure.
Force JDBC Batch Requests
Forces to use native JDBC batch request.