Enterprise Edition Home | Express Edition Home | Previous Page | Next Page   SQL Statements > PUT >

Naming Program Variables in PUT

When the INSERT statement is prepared (see PREPARE), you cannot use program variables in its VALUES clause, but you can represent values by a question-mark ( ? ) placeholder. List the program variables in the FROM clause of the PUT statement to supply the missing values.

The following ESQL/C example lists host variables in a PUT statement:

char answer [1] = 'y';
EXEC SQL BEGIN DECLARE SECTION;
   char ins_comp[80];
   char u_company[20];
EXEC SQL END DECLARE SECTION;

main()
{
   EXEC SQL connect to 'stores_demo';
   EXEC SQL prepare ins_comp from
      'insert into customer (customer_num, company) values (0, ?)';
   EXEC SQL declare ins_curs cursor for ins_comp;
   EXEC SQL open ins_curs;

   while (1)
      {
      printf("\nEnter a customer: ");
       gets(u_company);
      EXEC SQL put ins_curs from :u_company;
      printf("Enter another customer (y/n) ? ");
      if (answer = getch() != 'y')
         break;
      }
   EXEC SQL close ins_curs;
   EXEC SQL disconnect all;
}

Indicator variables are optional, but you should use an indicator variable if the possibility exists that output_var might contain a NULL value. If you specify the indicator variable without the INDICATOR keyword, you cannot put a blank space between output_var and indicator_var.

Using the USING Clause

If you do not know the number of parameters to be supplied at runtime or their data types, you can associate input values from a system-descriptor area or an sqlda structure. Both of these descriptor structures describe the data type and memory location of one or more values to replace question-mark ( ? ) placeholders.

Each time the PUT statement executes, the values that the descriptor structure describes are used to replace question-mark ( ? ) placeholders in the INSERT statement. This process is similar to using a FROM clause with a list of variables, except that your program has full control over the memory location of the data values.

Enterprise Edition Home | Express Edition Home | [ Top of Page | Previous Page | Next Page | Contents | Index ]