Declaring Host Variables

From InterBase

Go Up to Requirements for All Applications (Embedded SQL Guide)

A host variable is a standard host-language variable used to hold values read from a database, to assemble values to write to a database, or to store values describing database search conditions. SQL uses host variables in the following situations:

  • During data retrieval, SQL moves the values in database fields into host variables where they can be viewed and manipulated.
  • When a user is prompted for information, host variables are used to hold the data until it can be passed to InterBase in a SQL INSERT or UPDATE statement.
  • When specifying search conditions in a SELECT statement, conditions can be entered directly, or in a host variable. For example, both of the following SQL statement fragments are valid WHERE clauses. The second uses a host-language variable, country, for comparison with a column, COUNTRY:
… WHERE COUNTRY = 'Mexico';
… WHERE COUNTRY = :country;

One host variable must be declared for every column of data accessed in a database. Host variables may either be declared globally like any other standard host-language variable, or may appear within a SQL section declaration with other global declarations. For more information about reading from and writing to host variables in SQL programs, see Working with Data.

Host variables used in SQL programs are declared just like standard language variables. They follow all standard host-language rules for declaration, initialization, and manipulation. For example, in C, variables must be declared before they can be used as host variables in SQL statements:

int empno; char fname[26], lname[26];

For compatibility with other SQL variants, host variables can also be declared between BEGIN DECLARE SECTION and END DECLARE SECTION statements.


Advance To: