Informix-ESQL/C Programmer's Manual
Chapter 14: Using Dynamic SQL
Home
Contents
Index
Master Index
New Book
SQL Statements That Are Not Known at Compile Time
An SQL statement that is
not
known at compile time is usually one that the user enters in an interactive application. When you write an interactive database-query application like DB-Access, you do not know in advance which databases, tables, or columns the user wants to access, or what conditions the user might apply in a
WHERE
clause. If an ESQL/C application interprets and runs SQL statements that the end user enters, this application does not know what type of information is to be stored in host variables until after the user enters the statement at runtime.
For example, if a program contains the following
DELETE
statement, you know the number of values and the data types that you will receive, based on the affected columns:
DELETE FROM customer WHERE city = ? AND lname > ?
You can define host variables whose data types are compatible with the data they receive. However, suppose your program provides a prompt for the user such as:
Enter a DELETE statement for the stores7 database:
In this case, you do not know until runtime either the name of the table on which the
DELETE
will take place or the columns that will be listed in the
WHERE
clause. Therefore, you cannot declare the necessary host variables.
You can dynamically determine a prepared SQL statement as well as information about the tables and columns it accesses with the
DESCRIBE
statement and the dynamic-management structures. For more information, see
Chapter 15, "Determining SQL Statements."
Informix-ESQL/C Programmer's Manual
, version 9.1
Copyright © 1998, Informix Software, Inc. All rights reserved.