Using indicator variables with host output and result variables

When you associate an indicator variable with an output or result variable, Client-Library automatically sets it to one of the following values in Table 4-2:

Table 4-2: Indicator variable values when used with output or result variable

Value

Meaning

-1

The corresponding database column in Adaptive Server contains a null value.

0

A non-null value was assigned to the host variable.

>0

An overflow occurred while data was being converted for the host variable. The host variable contains truncated data. The positive number represents the length, in bytes, of the value before it was truncated.

The following example demonstrates associating the indicator variable indic with the result variable id:

exec sql begin declare section; 
 CS_CHAR          id[6]; 
 CS_SMALLINT      indic; 
 CS_CHAR          pub_name[41];  
 exec sql end declare section; 
  
 exec sql select pub_id into :id indicator :indic  
     from titles where title  
     like "%Stress%";
  
 if (indic == -1)
 { 
     printf("\npub_id is null"); 
 } 
 else  
 { 
     exec sql select pub_name into :pub_name
         from publishers where pub_id = :id;
     printf("\nPublisher: %s", pub_name);
 }