2. Embedded SQL for C : C Variables and Data Types : Variable Usage : Pointer Variables
 
Share this page                  
Pointer Variables
The following syntax refers to a pointer variable:
:*{*}pointername
Note:   
Refer to the variable indirectly, because only scalar-valued elements (integers, floating-point, and character strings) are legal SQL values.
When you declare the variable, the preprocessor notes the number of preceding asterisks. Later references to the variable must have the same indirection level. The indirection level is the sum of the number of pointer operators (asterisks) preceding the variable declaration name and the number of array subscripts following the name.
A character string, declared as a pointer to a character, is not considered a pointer and cannot be subscripted in order to reference a single character. As with arrays, single characters are illegal string values because any character string value must be null-terminated. For example, assuming the following declaration:
char *abc = "abc";
you could not access the character "a" with the reference:
:*abcExternal compiled forms that you declare as:
UNIX:
extern int *compiled_formname;
VMS:
globalref *compiled_formname;
These external compiled forms must not include any indirection when referenced in the addform statement.
As with standard C, any variable that you can denote with pointer indirection can also be denoted with array subscripting. This is true because the preprocessor only records the number of indirection levels used when referencing a variable. For example, if you declare a variable as a pointer:
int *age_pointer;
it can be referenced as either a pointer:
:*age_pointer;
or an array:
:age_pointer[0];
The following example uses a pointer to insert integer values into a database table.
Example: Pointer variable usage
exec sql begin declare section;
        int *numptr;
 exec sql end declare section;
 static int numarr[6] = {1, 2, 3, 4, 5, 0};

for (numptr = numarr; *numptr; numptr++)
    exec sql insert into items (number) values (:*numptr);