SQL/MX 2.x Reference Manual (H06.04+)

Embedded-Only SQL/MX Statements
HP NonStop SQL/MX Reference Manual540440-003
3-7
C Examples of ALLOCATE DESCRIPTOR
hvdouble1 = 1.0E-76;
EXEC SQL PREPARE insert_q FROM :insert_buf;
printf("SQLCODE after prepare insert_q - 1 is %d\n",
SQLCODE);
Exec SQL execute insert_q using :hvdouble1;
printf("SQLCODE after insert - 3 is %d \n", SQLCODE);
Defining Values in the Descriptor Area
All values in all items of the descriptor area are initially undefined. To define values,
use a DESCRIBE statement or explicitly set values with a SET DESCRIPTOR
statement.
Descriptor Names
You cannot have more than one descriptor allocated with the same name at the same
time within the same scope. For example, this sequence from a C program is not valid:
strcpy(descname1,"SQLDA1");
desc_max1 = 2;
EXEC SQL ALLOCATE DESCRIPTOR :descname1 WITH MAX :desc_max1;
strcpy(descname2,"SQLDA1");
desc_max2 = 3;
EXEC SQL ALLOCATE DESCRIPTOR :descname2 WITH MAX :desc_max2;
The second ALLOCATE DESCRIPTOR fails because SQLDA1 has already been
allocated.
C Examples of ALLOCATE DESCRIPTOR
This example uses an SQL string literal as the descriptor name:
desc_max = 1;
EXEC SQL ALLOCATE DESCRIPTOR 'in_sqlda' WITH MAX :desc_max;
This example uses a host variable as the descriptor name:
...
EXEC SQL BEGIN DECLARE SECTION;
VARCHAR desc_name[20];
long desc_max;
...
EXEC SQL END DECLARE SECTION;
...
strcpy(desc_name, "in_sqlda");
desc_max = 1;
EXEC SQL ALLOCATE DESCRIPTOR :desc_name WITH MAX :desc_max;
...