The ifx_cl_card() function
The ifx_cl_card() function returns the cardinality of the specified collection type host variable.
Syntax
mint ifx_cl_card(collp, isnull)
ifx_collection_t *collp;
mint *isnull;
- collp
- A pointer to the name of the collection host variable in the application.
- isnull
- Set to
1
if the collection is null,0
otherwise
Usage
The ifx_cl_card() function enables you to determine the number of elements in a collection, whether the collection is empty, and whether the collection is null.
Return codes
- 0
- The collection is empty.
- >0
- The number of elements in the collection.
- <0
- An error occurred.
Example
This sample program is in the ifx_cl_card.ec file
in the demo directory.
/*
* Check the cardinality of the collection variable when
* the data is returned from the server
*/
main()
{
exec sql begin declare section;
client collection myset;
exec sql end declare section;
mint numelems = 0;
mint isnull = 0;
exec sql allocate collection ::myset;
exec sql create database newdb;
exec sql create table tab (col set(int not null));
exec sql insert into tab values ("set{}");
exec sql select * into :myset from tab;
if ((ifx_cl_card(myset, &isnull) == 0) && isnull == 0)
printf("collection is empty\n");
else if ((ifx_cl_card(myset, &isnull) == 0) && isnull == 1)
printf("collection is null\n");
else if ((numelems = ifx_cl_card(myset, &isnull))> 0)
printf("number of elements is %d\n", numelems);
else
printf("error occurred\n");
exec sql update tab set col = ’set{1,2,3}’;
exec sql select * into :myset from tab;
if ((ifx_cl_card(myset, &isnull) == 0) && isnull == 0)
printf("collection is empty\n");
else if ((ifx_cl_card(myset, &isnull) == 0) && isnull == 1)
printf("collection is null\n");
else if ((numelems = ifx_cl_card(myset, &isnull))> 0)
printf("number of elements is %d\n", numelems);
else
printf("error occurred\n");
exec sql update tab set col = NULL;
exec sql select * into :myset from tab;
if ((ifx_cl_card(myset, &isnull) == 0) && isnull == 0)
printf("collection is empty\n");
else if ((ifx_cl_card(myset, &isnull) == 0) && isnull == 1)
printf("collection is null\n");
else if ((numelems = ifx_cl_card(myset, &isnull))> 0)
printf("number of elements is %d\n", numelems);
else
printf("error occurred\n");
}
Output
collection is empty
number of elements is 3
collection is null