Defining Stored Procedures
Stored procedures are function-like interfaces to the data source that can be used to search, modify, or delete data. Stored procedures model actions that typically cannot be represented as SELECT, INSERT, UPDATE, or DELETE statements. Modeling stored procedures is a similar process to modeling tables in that you can use the same built-in data processing operations to implement stored procedures.
Stored Procedure Schemas vs. Table Schemas
With minor modifications, you can follow the same process to create a stored procedure that you would follow to add support for INSERT, UDPATE, and DELETE statements: define stored procedures in .rsb files, which, like .rsd files, consist of an info block and scripts that call data processing operations.
Instead of columns, the info block defines the input and output parameters of the stored procedure. Instead of the attr element, define inputs with the input element in the info block.
As with other SQL statements, when the stored procedure is executed, the _input item contains the input parameters. You can use the _input item to map the stored procedure inputs to the operation inputs.
As with table schemas, you can use the info block to process the response. Describe the outputs of a stored procedure with the output attribute in the info block. In the output attributes, you can specify the XPaths to extract nodes of hierarchical data.
Example Stored Procedure
The following stored procedure retrieves a Person record given their Id. This fully functional schema shows how to build the request and use XPaths to parse the response.
A stored procedure executes the GET method of the schema. Build the API request in this method: check that required inputs were provided and alert the user otherwise with the api:validate keyword. Use Value Formatters to simplify working with strings, dates, and math expressions.
<api:script xmlns:api="http://www.rssbus.com/ns/rsbscript/2"> <api:info title="GetODataPersonById" description="Retrieves the OData Person specified by Id."> <output name="ID" other:xPath="/feed/entry/content/properties/ID" /> <output name="EmployeeID" other:xPath="/feed/entry/content/properties/EmployeeID" /> <output name="Name" other:xPath="/feed/entry/content/properties/Name" /> <output name="TotalExpense" other:xPath="/feed/entry/content/properties/TotalExpense" /> <output name="HireDate" other:xPath="/feed/entry/content/properties/HireDate" /> <output name="Salary" other:xPath="/feed/entry/content/properties/Salary" /> </api:info> <api:set attr="uri" value="http://services.odata.org/V4/OData/(S(5cunewekdibfhpvoh21u2all))/OData.svc/Persons" /> <!-- The XPath attribute of the schema splits the XML into rows based on elements that repeat at the same level. --> <api:set attr="XPath" value="/entry/" /> <!-- See the xmlproviderGet page in the Operations subchapter to set any needed HTTP parameters. --> <api:set attr="ContentType" value="application/atom+xml" /> <!-- The GET method corresponds to EXECUTE. Within the script block, you can see the URI modified to append a query string parameter. The results of processing are pushed to the schema's output. --> <api:script method="GET"> <api:set attr="method" value="GET"/> <api:set attr="uri" value="[uri]([_input.Id])?$format=atom"/> <api:call op="xmlproviderGet"> <api:push /> </api:call> </api:script> </api:script>
See the API Script Reference for more information on the keywords used in this section: