An example of using indicator variables
- Determine if truncation has occurred on a character array
If you define lname in the customer table with a length that is longer than 15 characters, nameind contains the actual length of the lname column. The name host variable contains the first 15 characters of the lname value. (The string name must be terminated with a null character.) If the family name of the company representative with customer_num = 105 is shorter than 15 characters, Informix® ESQL/C truncates only the trailing blanks.
- Check for a null value
If company has a null value for this same customer, compind has a negative value. The contents of the character array comp cannot be predicted.
EXEC SQL BEGIN DECLARE SECTION;
char name[16];
char comp[20];
short nameind;
short compind;
EXEC SQL END DECLARE SECTION;
EXEC SQL select lname, company
into :name INDICATOR :nameind, :comp INDICATOR :compind
from customer
where customer_num = 105;
Using indicator variables with EXEC SQL and the colon (:) symbol uses the INDICATOR keyword to associate the main and indicator variables. This method complies with the ANSI standard.
$char name[16];
$char comp[20];
$short nameind;
$short compind;
$select lname, company
into $name$nameind, $comp$compind
from customer
where customer_num = 105;