Pointers as host variables

Use a pointer as a host variable if your program uses the pointer to input data to an SQL statement.

For example, the following figure shows how you can associate a cursor with a statement and insert values into a table.
Figure 1: Declaring a character pointer to input data
EXEC SQL BEGIN DECLARE SECTION;
   char *s;
   char *i;
EXEC SQL END DECLARE SECTION;

/* Code to allocate space for two pointers not shown */

s = "select * from cust_calls";
i = "NS";

⋮

EXEC SQL prepare x from :s;
EXEC SQL insert into state values (:i, 'New State');
The following figure shows how to use an integer pointer to input data to an INSERT statement.
Figure 2: Declaring an integer pointer to input data
EXEC SQL BEGIN DECLARE SECTION;
   short *i;
   int *o;
   short *s;
EXEC SQL END DECLARE SECTION;

short i_num = 3;
int o_num = 1002;
short s_num = 8;

i = &i_num;
o = &o_num;
s = &s_num;

EXEC SQL connect to 'stores7';
EXEC SQL insert into items values (:*i, :*o, :*s, 'ANZ', 5, 125.00);
EXEC SQL disconnect current; 

If you use a host variable that is a pointer to char to receive data from a SELECT statement, you receive a compile-time warning and your results might be truncated.