skip to main content
Designing and coding the IP : Update processing
 

Update processing

Implementing UPDATE processing in your IP is similar to that of SELECT processing, for finding matching rows. The difference is that when dam_isTargetRow returns DAM_TRUE, the row in the data source is updated with the values provided by the OpenAccess SDK SQL engine instead of a row being added to the result set.
If the IP finds a row in the data source that matches the WHERE condition, it should call dam_getUpdateRow to get the values for the columns that need to be updated. The OpenAccess SDK SQL engine returns the update values as a column-value pair. Each column-value pair is navigated by using dam_getFirstValueSet and dam_getNextValueSet. The data and the column handle are retrieved by using the dam_getValueToSet and dam_getColToSet functions.
The dam_describeCol function can be used to find the column number or name.
This query gets the row to use for updating:
DAM_HROW dam_getUpdateRow(DAM_HSTMT hstmt, DAM_HROW hRowTarget)
Use the current row that has been validated with the dam_isTargetRow(hRowTarget) as the source for values if the update values are defined by current column values.
This query requires the values of the current row before the OpenAccess SDK SQL engine can return values for the Update Row:
UPDATE emp SET salary = salary + salary * 0.1
This query gets the first column-value pair of the Update Row:
DAM_HROWELEM dam_getFirstValueSet(DAM_HSTMT hstmt, DAM_HROW hrow)
This query gets the next column-value of the Update Row.
DAM_HROWELEM dam_getNextValueSet(DAM_HSTMT hstmt)
This query gets the column handle for the Update Column in the Update Row.
DAM_HCOL dam_getColToSet(DAM_HROWELEM hRowElem)
This query gets the value of the Update Column in the Update Row.
int dam_getValueToSet(DAM_HROWELEM hRowElem, int iType, void **pData, int * piLen)
iType specifies how you want the value to be returned.
Note: iType must match the type of the column as defined in the schema or must be XO_TYPE_CHAR. Other conversions are not supported at this time. You can obtain the type of the column by using the dam_describeCol function on the column handle returned by the dam_getColToSet function.