RetrieveOrUpdateWithModels

Description

Retrieves or updates data for more than one DataWindow, DataWindowChild, or DataStore using the .NET DataStore Web API. Commit changes to the database automatically if all succeed; otherwise roll back all of the changes if any DataWindow failed.

Applies to

RestClient object

Syntax

objectname.RetrieveOrUpdateWithModels (ref batchdataobjects, urlName, {tokenrequest})

Argument

Description

objectname

A reference to the RestClient object.

batchdataobjects

The object which contains one or more DataWindow controls, DataStores, and child DataWindows to be retrieved or updated.

urlName

A string whose value is the URL of the .NET DataStore Web API.

tokenrequest

(Optional) A reference to the TokenRequest object for supporting OAuth 2.0. If this parameter is used, the token settings in the SetOAuthToken and SetJWTToken functions will be ignored.


SQL execution within the RetrieveOrUpdateWithModels API

With RetrieveOrUpdateWithModels, it is possible to add a simple SQL statement for execution in the REST API (execution is supported, but no return value). For example, add the execution of ls_sql in the RetrieveOrUpdateWithModelsAsync API in DataStoreService.cs:

//User additional data
var additionalData = request.AdditionalData;
            if (additionalData != null)
            {
                string ls_sql = additionalData.ToString();
                if (ls_sql.Length > 0 )
                {
                    dataContext.SqlExecutor.Execute(ls_sql);
                }                
            }

You can then pass the SQL to the RetrieveOrUpdateWithModels API from the front-end. For example, from PowerBuilder, you can call this function: BatchDataObjects.SetAdditionalData(sql) to pass the SQL.

Return value

Integer.

Returns 1 if the function succeeds or if no DataWindow control, DataStore, or child DataWindow is added to batchdataobjects.

Returns a negative value if an error occurs. If any argument's value is null, the method returns null.

Example

The following code example shows retrieving data for dw_emp and updating data for dw_dept and dw_emp using a .NET DataStore Web API:

Integer li_return, index
RestClient lnv_RestClient 
BatchDataObjects lnv_objects

lnv_RestClient = Create RestClient

lnv_objects.AddUpdatObject(dw_dept)
lnv_objects.AddUpdatObject(dw_emp)
lnv_objects.AddRetrieveObject(dw_emp, 129)

if lnv_objects.GetCount() <= 0 then
   MessageBox("Error", "Error when add dwControl to BatchDataObjects")
  return
end if

// Send request to .NET DataStore Service
li_return = lnv_RestClient.RetrieveOrUpdateWithModels (lnv_objects ,"http://localhost:5099/RetrieveOrUpdateWithModels") 

// Check the return value
if li_return = 1 then
    MessageBox("Success", "Return = " + String(ll_return))
else
index = lnv_objects.GetErrorIndex()
    if index > 0 then
       MessageBox("RetrieveOrUpdateWithModels Error(Index:" + String(index) + ")"
, "Error DB Code:"+ string(lnv_objects.GetSQLDBCode(index)) + "\r\n Error Message:" + lnv_objects.GetSQLErrText(index)
else
  //handle other error
    end if
end if

See also

RetrieveWithModel

UpdateWithModel