Enterprise Edition Home | Express Edition Home | Previous Page | Next Page   SQL Statements >

ALLOCATE ROW

Use the ALLOCATE ROW statement to allocate memory for a row variable. Only Dynamic Server supports this statement, which is an extension to the ANSI/ISO standard for SQL. Use this statement with ESQL/C.

Syntax

Read syntax diagramSkip visual syntax diagram>>-ALLOCATE ROW--variable--------------------------------------><
 
Element Description Restrictions Syntax
variable Name of a typed or untyped row variable to allocate Must be an unallocated ESQL/C row-type host variable Language specific

Usage

The ALLOCATE ROW statement allocates memory for a host variable that stores row-type data. To create a row variable, an ESQL/C program must do the following:

  1. Declare the row variable. The row variable can be a typed or untyped row variable.
  2. Allocate memory for the row variable with the ALLOCATE ROW statement.

The following example shows how to allocate resources with the ALLOCATE ROW statement for the typed row variable, a_row:

EXEC SQL BEGIN DECLARE SECTION;
   row (a int, b int) a_row;
EXEC SQL END DECLARE SECTION;
. . .
EXEC SQL allocate row :a_row;

The ALLOCATE ROW statement sets SQLCODE (the contents of sqlca.sqlcode) to zero (0) if the memory allocation operation was successful, or to a negative error code if the allocation failed.

You must explicitly release memory with the DEALLOCATE ROW statement. Once you free the row variable with the DEALLOCATE ROW statement, you can reuse the row variable.

Tip:
The ALLOCATE ROW statement allocates memory for an ESQL/C row variable only. To allocate memory for an ESQL/C collection variable, use the ALLOCATE COLLECTION statement.

When you use the same row variable in multiple function calls without deallocating it, a memory leak on the client computer results. Because there is no way to determine if a pointer is valid when it is passed, ESQL/C assumes that the pointer is not valid and assigns it to a new memory location.

Related Information

Related statements: ALLOCATE COLLECTION and DEALLOCATE ROW

For a discussion of complex data types in ESQL/C programs, see the IBM Informix ESQL/C Programmer's Manual.

Enterprise Edition Home | Express Edition Home | [ Top of Page | Previous Page | Next Page | Contents | Index ]