Determine the cardinality of a collection
The DataBlade API provides the mi_collection_card() function for obtaining the number of elements in a collection (its cardinality).
The following code fragment uses the mi_collection_card() function
to perform separate actions based on whether a collection is NULL
or has elements (possibly 0 elements):
MI_COLLECTION *collp;
mi_integer cardinality;
mi_boolean isnull;
/* Attach collp to a collection */
cardinality = mi_collection_card(collp, &isnull);
if ( isnull == MI_TRUE )
{
mi_db_error_raise(conn, MI_MESSAGE, "Warning: Collection is NULL.");
}
else
{
if ( cardinality > 0 )
{
/* Open collection and perform action on individual elements */
}
}