If the IP implementer wants to share statement or connection context information between EXECUTE operations and scalar function implementation, the IP should be implemented as described in this section.
Constant Scalar functions take control of query execution prior to IP EXECUTE. If the function is a non-constant function, the function is called after IP EXECUTE is called. If the IP supports constant and non-constant functions, it can have functions initialize global context after checking if global context is not already initialized.
The IP EXECUTE operation also checks and initializes the global query context. Either the constant-scalar functions or the IP EXECUTE sets up the global context. Non-constant scalar functions have access to existing global context. IP EXECUTE should use START_QUERY to setup global context and END_QUERY to release the global context. This ensures that all non-constant scalar functions gets evaluated before the IP releases the global context.
All scalar functions (constant or non-constant) can get access to IP_HDBC by calling dam_getInfo(DAM_INFO_IP_HDBC).
/* Global Statement Descriptor Area */
typedef struct xxx_gstatement_struct {
char sFuncName[DAM_MAX_ID_LEN+1]; /* Name of the scalar function used in query */
/* constant scalar functions can setup any information in this global structure.
Non constant functions can access any information initialized by IP execute */
strcpy(pgStmtDA->sFuncName, "abc");
}
ipExecute(IP_HDBC hdbc, DAM_HSTMT hstmt,...)
{
XXX_GSTMT_DA *pgStmtDA;
int iValueLen;
pgStmtDA = xxx_init_global_context(hstmt, pMemTree);
if (strlen(pgStmtDA->sFuncName) > 0) {
/* information setup by constant scalar function can be retrieved */
}
}
Note: Scalar functions are evaluated at the global context of the query. When executing join queries, if the IP uses dam_setIP_hstmt to save table information, scalar functions do not have access to individual table information. So if scalar functions were to call dam_getIP_hstmt, they would get NULL handle when processing join queries.