skip to main content
Table functions : Example : Providing schema for CURVALUE table function
 

Providing schema for CURVALUE table function

The following example demonstrates how to provide schema information of CURVALUE to the OpenAccess SDK.
To provide schema information of the CURVALUE table function to OpenAccess SDK:
1. In the OAIP_schemaW function, under ’case DAMOBJ_TYPE_TABLE:’ use dam_add_damobj_tableW() function to add the table function schema object. Before adding the object, use dam_isSchemaTableFunctionW() to check whether the schema object being added is a table function or a table.
if(dam_isSchemaTableFunctionW(pSearchTableObj))
{
if (xxx_is_matching_tableW(pSearchTableObj, XXX_QUALIFIER_NAME_W, XXX_USER_NAME_W,
OAL_WTEXT("CURVALUE")))
{
dam_add_damobj_tableW(pMemTree, pList, pSearchObj, XXX_QUALIFIER_NAME_W, XXX_USER_NAME_W,
OAL_WTEXT("CURVALUE"), OAL_WTEXT("TABLEFUNCTION"), NULL, NULL, NULL,
OAL_WTEXT("Current Details Table Function"));
}
}
Else
{
if (xxx_is_matching_tableW(pSearchTableObj, XXX_QUALIFIER_NAME_W, XXX_USER_NAME_W,
OAL_WTEXT("CURVALUE_ALIAS")))
{
dam_add_damobj_tableW(pMemTree, pList,pSearchObj,XXX_QUALIFIER_NAME_W,XXX_USER_NAME_W,
OAL_WTEXT("CURVALUE_ALIAS"),OAL_WTEXT("TABLE"),NULL,NULL,NULL,
OAL_WTEXT("Current Values Table"));
}
}
2. In the OAIP_schemaW function, under ‘case DAMOBJ_TYPE_COLUMN:’use pSearchColumnObj->pTableObj to check whether the column belongs to a table or to a table function. For table functions, pSearchColumnObj->pTableObj is NOT NULL; for a table, it is set to NULL.
Pass the search object to dam_getTableFunctionArgList()and obtain the table function’s parameter list. Use dam_getFirstValExp() and dam_getNextValExp() to iterate through the list of parameters; then use dam_add_damobj_column() to add the table function column schema object.
if (pSearchColumnObj)
{
/*If pSearchColumnObj->pTableObj is not NULL then IP Schema needs to return
columns information for TableFunction*/
bIsTableFunction = pSearchColumnObj->pTableObj ? DAM_TRUE:DAM_FALSE;
}
...
 
#define MAX_ARGS_FOR_CURVALUE_F 5
/* CURVALUE table functions columns */
 
if (xxx_is_matching_columnW(pSearchColumnObj, XXX_QUALIFIER_NAME_W, XXX_USER_NAME_W,
OAL_WTEXT("CURVALUE")))
{
 
char *pArg1 = NULL;
int len = 0, iRetCode = 0, iVal = 0, *piVal = NULL, iColCount = 0;
DAM_HVALEXP_LIST hValExpList = NULL;
DAM_HVALEXP hValExp = NULL;
OAWCHAR sColName[DAM_MAX_ID_LEN+1];
hValExpList = dam_getTableFunctionArgList(pSearchColumnObj->pTableObj);
if(hValExpList != NULL)
{
hValExp = dam_getFirstValExp(hValExpList);
while (hValExp)
{
iColCount++;
if(iColCount <= MAX_ARGS_FOR_CURVALUE_F)
{
int iXoType;
 
iXoType = dam_getValueTypeOfExp(pMemTree,hValExpList,hValExp);
iRetCode = dam_getValueOfExp(pMemTree, hValExpList, hValExp,
XO_TYPE_CHAR, &pArg1, &len);
if(iRetCode == DAM_FAILURE) return DAM_FAILURE;
oambstowcs(sColName,pArg1,sizeof(sColName)/sizeof(OAWCHAR));
dam_add_damobj_columnW(pMemTree, pList, pSearchObj, XXX_QUALIFIER_NAME_W,
XXX_USER_NAME_W,OAL_WTEXT("CURVALUE"), sColName,
12, OAL_WTEXT("VARCHAR"), 240,
240, DAMOBJ_NOTSET, DAMOBJ_NOTSET,
XO_NO_NULLS, DAMOBJ_NOTSET, NULL, NULL,
DAMOBJ_NOTSET, 0, OAL_WTEXT("Column of the CURVALUE table function"));
}
hValExp = dam_getNextValExp(hValExpList);
}
 
/* To limit the number of columns to 5*/
 
if(iColCount > MAX_ARGS_FOR_CURVALUE_F)
{
char dam_msgBuf[129];
sprintf(dam_msgBuf, "Invalid Number of Parameters to the Table
Function:%s. Max. Number of Parameters is %d", "CURVALUE",MAX_ARGS_FOR_CURVALUE_F);
dam_addError(NULL, NULL, DAM_IP_ERROR, 0, dam_msgBuf);
return DAM_FAILURE;
}
}
3. In the OAIP_schemaW function, under ‘case DAMOBJ_TYPE_STAT:’ use pSearchStatObj->pTableObj to check whether the statistics belong to a table or a table function. For CURVALUE pSearchColumnObj->pTableObj is NOT NULL; for a table it is set to NULL.
Then use dam_add_damobj_stat() to add the statistic schema objects for CURVALUE.
if(pSearchStatObj)
{
/*If pSearchColumnObj->pTableObj is not NULL then IP Schema needs
to return statistics information for TableFunction*/
bIsTableFunction = pSearchStatObj->pTableObj ? DAM_TRUE : DAM_FALSE ;
}
...
 
if(bIsTableFunction && !sl_stricmp(pSearchStatObj->table_name,"CURVALUE"))
{
char *pArg1;
int len;
 
hValExpList = dam_getTableFunctionArgList(pSearchStatObj->pTableObj);
 
if(hValExpList != NULL)
{
hValExp = dam_getFirstValExp(hValExpList);
if (hValExp)
{
iRetCode = dam_getValueOfExp(pMemTree, hValExpList, hValExp,
XO_TYPE_CHAR, &pArg1, &len);
if(iRetCode == DAM_FAILURE) return DAM_FAILURE;
}
/*Adding the table function index */
dam_add_damobj_stat(pMemTree, pList,
pSearchObj,XXX_QUALIFIER_NAME,XXX_USER_NAME,"CURVALUE",0,NULL,
"CURVALUE_TABFUNC_INDX",3,1,pArg1,
"A",DAMOBJ_NOTSET,DAMOBJ_NOTSET,NULL);
}
}