EGL Reference Guide for iSeries

prepare

The EGL prepare statement specifies an SQL PREPARE statement, which optionally includes details that are known only at run time. You run the prepared SQL statement by running an EGL execute statement or (if the SQL statement returns a result set) by running an EGL open or get statement.



Syntax diagram for the prepare statement

preparedStatementID
An identifier that relates the prepare statement to the execute, open, or get statement.
stringExpression
A string expression that contains a valid SQL statement.
SQL record name
Name of an SQL record. Specifying this name has two benefits:

Another example is as follows:

  myString = 
    "insert into myTable " +  "(empnum, empname) " +
    "value ?, ?";
 
  try
    prepare myStatement 
      from myString;
  onException
    myErrorHandler(12);      // exits the program
  end
 
  try
    execute myStatement 
    using :myRecord.empnum,
          :myRecord.empname;
  onException
    myErrorHandler(15);
  end

As shown in the previous examples, the developer can use a question mark (?) where a host variable should appear. Then, the name of the host variable used at run time is placed in the using clause of the execute, open, or get statement that runs the prepared statement.

A prepare statement that acts on a row of a result set may include a phrase of the format where current of resultSetIdentifier. This technique is valid only in the following situation:

An example is as follows:

	 prepare prep02 from
    "update myTable " +
    "set empname = ?,  empphone = ?  where current of x1" ;
 
  execute prep02 using empname, empphone ;


Related concepts
References to parts
Record types and properties
SQL support


Related tasks
Syntax diagram


Related reference
add
close
delete
Exception handling
execute
get
get next
get previous
I/O error values
EGL statements
open
replace
SQL item properties
String expressions


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]