informix
Informix Guide to SQL: Syntax
SQL Statements

ALLOCATE COLLECTION

Use the ALLOCATE COLLECTION statement to allocate memory for a collection variable.

Use this statement with ESQL/C.

Syntax

Element Purpose Restrictions Syntax
variable Name that identifies a typed or untyped collection variable for which to allocate memory The variable must be the name of an unallocated ESQL/C collection host variable. Name must conform to language-specific rules for variable names.

Usage

The ALLOCATE COLLECTION statement allocates memory for a variable that stores collection data. To create a collection variable for an ESQL/C program, perform the following steps:

  1. Declare the collection variable as a client collection variable in an ESQL/C program.
  2. The collection variable can be a typed or untyped collection variable.

  3. Allocate memory for the collection variable with the ALLOCATE COLLECTION statement.

The ALLOCATE COLLECTION statement sets SQLCODE (sqlca.sqlcode) to zero (0) if the memory allocation was successful and to a negative error code if the allocation failed.

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

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

Examples

The following example shows how to allocate resources with the ALLOCATE COLLECTION statement for the untyped collection variable, a_set:

The following example uses ALLOCATE COLLECTION to allocate resources for a typed collection variable, a_typed_set:

Related Information

Related examples: Refer to the collection variable example in PUT

Related statements: ALLOCATE ROW and DEALLOCATE COLLECTION

For a discussion of collection data types, see the Informix ESQL/C Programmer's Manual.


Informix Guide to SQL: Syntax, Version 9.2
Copyright © 1999, Informix Software, Inc. All rights reserved