JDBC Driver for REST

Build 20.0.7654

UPDATE Execution

When an UPDATE statement is executed, the driver executes the MERGE method of the schema, where you can build the HTTP update request.

To see this method in a complete example, refer to Customizing Schemas.

Execute Updates to REST

In the MERGE method, the _input item, one of the Items in API Script, contains the columns to update. For example, consider the following statement:

UPDATE Persons 
SET Name='Ana Trujilo'
WHERE Id = '7' 

You can use the _input item's attributes to set these column values in the HTTP update request. In the OData API, this can be an HTTP PUT or PATCH. The PUT data to make the preceding update in the OData API is below:

<entry xmlns:d="http://docs.oasis-open.org/odata/ns/data" xmlns:m="http://docs.oasis-open.org/odata/ns/metadata" xmlns="http://www.w3.org/2005/Atom">
  <category scheme="http://docs.oasis-open.org/odata/ns/scheme" term="ODataDemo.Person" />
  <content type="application/xml">
      <d:ID m:type="Edm.Int32">4</d:ID>
        <d:Name m:type="Edm.String">Ana Trujilo</d:Name>
In the example schema's corresponding MERGE method, the required column, the primary key, is validated and then used in the PUT data and the URL. You can check that an input was provided and alert the user otherwise with the api:validate keyword.

After validating that the needed attributes exist, you can set the column values in the PUT data. Set the "data" attribute to the PUT data -- the body of the api:set keyword is convenient for setting long or multiline values like this.

The api:call keyword invokes the operation that will make the HTTP request. Before invoking the operation, use api:set to set the method attribute to the HTTP method you want within the scope of the api:script keyword.

<api:script method="MERGE">
  <api:set attr=method value="PUT"/>
  <api:validate attr="_input.Id" desc="An Id is required to update." />
  <api:set attr="data">
    <entry xmlns:d="http://docs.oasis-open.org/odata/ns/data" xmlns:m="http://docs.oasis-open.org/odata/ns/metadata" xmlns="http://www.w3.org/2005/Atom">
      <api:set attr="uri" value="[uri]([_input.Id])" />
      <category scheme="http://docs.oasis-open.org/odata/ns/scheme" term="ODataDemo.Person" />
      <content type="application/xml">
          <d:ID m:type="Edm.Int32">[_input.Id]</d:ID>
          <api:check attr="_input.Name">
            <d:Name m:type="Edm.String">[_input.Name]</d:Name>
  <api:call op="xmlproviderGet"/>

Access the Components of UPDATE Statements

In the MERGE method, the _query item contains the following attributes:

queryThe SQL statement, as in the following statement:
UPDATE Account SET Name='John' WHERE Id = @myId
tableThe table in the SQL statement. For example, Account in the preceding query.
criteriaThe WHERE clause of the statement. For example, the following WHERE clause in the example:
Id = @myId
nullupdatesThe columns of an UPDATE statement, separated by commas, that contain a null value or a null parameter value.

Keyword Reference

See the API Script Reference for more information on the keywords used in this section:

Copyright (c) 2020 CData Software, Inc. - All rights reserved.
Build 20.0.7654