Define host variables by placing them within a declaration section. Host variables are declared by surrounding the normal C variable declarations with BEGIN DECLARE SECTION and END DECLARE SECTION statements.
Whenever you use a host variable in a SQL statement, you must prefix the variable name with a colon (:) so the SQL preprocessor knows you are referring to a (declared) host variable and distinguish it from other identifiers allowed in the statement.
You can use host variables in place of value constants in any SQL statement. When the database server executes the command, the value of the host variable is read from or written to each host variable. Host variables cannot be used in place of table or column names.
The SQL preprocessor does not scan C language code except inside a declaration section. Initializers for variables are allowed inside a declaration section, while typedef types and structures are not permitted.
The following sample code illustrates the use of host variables with an INSERT command. The variables are filled in by the program and then inserted into the database:
/* Declare fields for personal data. */ EXEC SQL BEGIN DECLARE SECTION; long employee_number = 0; char employee_name; char employee_initials; char employee_phone; EXEC SQL END DECLARE SECTION; /* Fill variables with appropriate values. */ /* Insert a row in the database. */ EXEC SQL INSERT INTO Employee VALUES (:employee_number, :employee_name, :employee_initials, :employee_phone );
|Envoyer votre avis sur cette page par email.||Copyright © 2009, iAnywhere Solutions, Inc. - SQL Anywhere 11.0.1|