ALLBASE/SQL Reference Manual (36216-90216)

466 Chapter11
SQL Statements E - R
PREPARE
PREPARE
The PREPARE statement dynamically preprocesses an SQL statement for later execution.
Scope
ISQL or Application Programs
SQL Syntax
PREPARE [REPEAT]{
StatementName
[
Owner.
]
ModuleName
[(
SectionNumber
)]}
[IN
DBEFileSetName
]FROM {
‘String’
:HostVariable
}
Parameters
REPEAT specifies the use of semi-permanent sections for queries. Unlike temporary
sections, semi-permanent sections are retained in memory until the
DBEnvironment session ends, not when the current transaction ends.
To improve performance, you can set the Authorize Once per Session flag
to ON with the SQLUtil ALTDBE command when using semi-permanent
sections. However, you must take care to ensure thata prepared statement
is not executed after authorization has been revoked from the object that
contains that statement.
StatementName
This option of the PREPARE statement is used in an application program;
it cannot be used interactively. Refer to the ALLBASE/SQL application
programming guide for the language you are using to determine whether
this statement is supported in that language.
StatementName
specifies a name for the statement being preprocessed.
You reference
StatementName
in an EXECUTE statement later in the
current transaction to execute the dynamically preprocessed statement.
StatementName
must conform to the ALLBASE/SQL rules for a basic
name given in the "Names" chapter. Two PREPARE statements in an
application program cannot specify the same
StatementName
.
When necessary, you use the DESCRIBE statement to determine whether
the prepared statement is a SELECT statement. If so, other information
provided by the DESCRIBE statement helps you determine how much
storage to dynamically allocate for the query result; then you reference the
StatementName
in a DECLARE CURSOR statement and use the cursor to
execute the dynamically preprocessed SELECT statement.
If it is possible that dynamic parameters are present in the prepared
statement, you must use the DESCRIBE statement with the INPUT clause.
If dynamic parameters are present, the appropriate data buffer or host
variables must be loaded with the values of any dynamic parameters
before the statement can be executed.