To allocate memory yourself

To specify that you are allocating the memory to store data for an lvarchar host variable you must first call ifx_var_flag(), giving the address of the lvarchar pointer and setting the flag value to zero (0), as the following example shows:
ifx_var_flag(&mypoly, 0);
Next you must fetch the data into sqlda or a system descriptor structure. You can then use the ifx_var_getllen() function to obtain the length of the data and use the ifx_var_alloc() function to allocate memory of that size.
#include <stdio.h>
exec sql include “polyvar.h” /* includes udt - polygon_type */

main()
{
   exec sql begin declare section;
      lvarchar ‘polygon_type’ *mypoly1
      char *buffer;
      int size, p_id, len;
   exec sql end declare section;

   ifx_var_flag(&mypoly1, 0); /* specifies that appl. will allocate 
memory */
   exec sql select poly into :mypoly1 from polygon_tab where p_id = 1;
   if ( ifx_var_getlen(&mypoly1) > 0 ) { /* If select returns valid data 
                                         */
   buffer = (char *)ifx_var_getdata(&mypoly1); /*Access data in 
                                                * mypoly1*/
   printf(“Length of data : %ld \n”, (int)ifx_var_getlen(&mypoly) );
   ifx_var_dealloc(&mypoly1); /* Always users responsibility to free */
}

Copyright© 2019 HCL Technologies Limited