/*****************************************************************************
**
** Function name:
**
** MyShapeObjectLength
**
** Description:
**
** This is an R-Tree support function which enables the
** server to use a fast method of building an R-Tree index.
**
** Special Comments:
**
** The SQL function signature for this function is
** "ObjectLength (UDT, pointer)". This requires an explanation:
**
** The purpose of the first argument is to provide function signature
** uniqueness, since you must declare a separate ObjectLength function
** for each subtype in that can participate in the opclass. In reality
** the server will pass an lvarchar containing the subtype name,
** and it will be lower case.
**
** The second argument is declared to be an SQL pointer (i.e. void *);
** in reality it is a pointer to an integer. You must not allocate
** space for this returned value; the server will allocate it for you.
**
** Parameters:
**
** mi_lvarchar *typename Type name of this UDT (e.g. 'MyShape')
** mi_integer *maxlen Returned value, max length of object
** MI_FPARAM *fp UDR function parameter & state info.
**
** Return value:
**
** mi_integer MI_OK if success, MI_ERROR if problems.
**
*****************************************************************************/
UDREXPORT mi_integer
MyShapeObjectLength (mi_lvarchar *typename,
mi_integer *maxlen,
MI_FPARAM *fp)
{
mi_char *col_type_name;
SHAPE_TRACE_ENTER (MyShapeObjectLength);
col_type_name = mi_lvarchar_to_string (typename);
if (strcmp (col_type_name, "myshape") == 0)
{
/*
* This is a supertype column. It could contain any
* combination of points, boxes, or circles, so return
* the size of the largest possible subtype.
*/
*maxlen = sizeof(MyShapeHdr) + sizeof(MyBoxData);
}
else if (strcmp (col_type_name, "mypoint") == 0)
{
*maxlen = sizeof(MyShapeHdr) + sizeof(MyPointData);
}
else if (strcmp (col_type_name, "mybox") == 0)
{
*maxlen = sizeof(MyShapeHdr) + sizeof(MyBoxData);
}
else if (strcmp (col_type_name, "mycircle") == 0)
{
*maxlen = sizeof(MyShapeHdr) + sizeof(MyCircleData);
}
else
{
mi_db_error_raise (NULL, MI_EXCEPTION,
"unknown column type name", (mi_char *) 0);
}
SHAPE_TRACE_EXIT (MyShapeObjectLength);
return MI_OK;
}