sqlalloc() — Allocate Dynamic Memory

Allocates memory to hold the DATA (and INDICATOR) values for the SQLVAR_T component of the SQL descriptor area (SQLDA_T structure).

On successful completion, sqlalloc() returns a pointer to the allocated storage; otherwise it returns a 0 pointer value:

SYNTAX
char *
sqlalloc ( nbytes )
  int  nbytes;    /* INPUT */ 

nbytes

The number of bytes to allocate for the DATA or INDICATOR components for an SQLVAR_T structure of the SQLDA_T structure. For the DATA component, you typically use a value for nbytes based on the SQL data type of the column (the TYPE component of the column’s SQLVAR_T structure). Include an extra byte for any NULL terminator or other extra characters that the data type uses. If you can set the column to the unknown value (i.e., the value of the NULLABLE member of the SQLVAR_T structure is 1), also allocate storage for the INDICATOR component with the length sizeof (long).

NOTES

EXAMPLE

In this example, the for statement assigns psqlvar to each column (SQLVAR_T structure) of an SQL descriptor area (assumed to be allocated contiguously). The body of the loop allocates alloclen bytes to each data element, set according to the data type of the column. For a complete listing of this example, see the alloc_disp_cols() function in the dyndemo.cc sample ESQL source file provided with your installation:

#include "proesql.h"
struct SQLDA_T				*psqlda;
            .
            .
            .
struct SQLVAR_T				*psqlvar;
            .
            .
            .
for (psqlvar = psqlda->SQLVAR[0]; . . . ; . . . psqlvar++)
{
            .
            .
    psqlvar->DATA = (char *) sqlalloc(alloclen);

    /* If you expect any NULL values, you must set the INDICATOR
       pointer here. Memory is allocated for a C long for each 
       column that can be NULL. */
      
    if (psqlvar->NULLABLE)
        psqlvar->INDICATOR = (long *)sqlalloc(sizeof(long));
            .
            .
            .
} 

SEE ALSO

sqlfree() — Deallocate Dynamic Memory, proesql.h


Copyright © 2004 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095