skip to main content
Designing and coding the IP : User defined scalar functions : Using scalar functions
 

Using scalar functions

You can implement your IP to handle scalar functions that have a column as its single argument in one of two ways:
The IP supplies the value of the column and the OpenAccess SDK SQL engine calls the scalar function that is applied on each column value for each row that is returned. This is the default behavior.
The IP supplies the value of the column and the scalar function is not applied to the value. In the case, when OpenAccess SDK SQL engine encounters a scalar function that is registered to be mapped as a column in select-list/search expression/Group By/Order By and containing a single column reference, the OpenAccess SDK SQL engine replaces the scalar function with the value of the column.
For details on registering a scalar function to be used as a column, refer to the specific OpenAccess SDK Programmer's Reference for your programming language.
In the following example, name is the scalar function and object is the single column argument.
SELECT name(object), vendor, supplier FROM tablex
In this example, the IP supplies the value of the column named object and the SQL engine, by default, calls the name scalar function for each row that is being returned.
In this example, when the IP is implemented to register a scalar function as a column, the IP supplies the value of the column named object and the SQL engine does not apply the name scalar function to the value of object.
When the IP uses dam_getFirstCol()/dam_getNextCol() to iterate the list of columns in use, the IP can call dam_describeColScalar to check if the column is a scalar function and if it is then perform the scalar function evaluation and add the result using dam_addValToRow.