EXECUTE (E-SQL)

The EXECUTE statement runs a prepared embedded SQL statement.

Syntax

EXECUTE prepared_stmt_name [USING DESCRIPTOR :sqlda_struct |
USING :hvar [,...]]

Arguments
prepared_stmt_name
Is an SQL statement that was previously prepared.
sqlda_struct
Is a SQLDA data structure that was previously declared and that contains a description of the input values.
hvar
Is one or more input host variables.
Remarks

The EXECUTE statement processes dynamic SQL statements. It runs the specified prepared SQL statement after it substitutes values for any parameter markers (?) present. (Prepared statements are created by using the PREPARE statement.) Only statements that do not return results are supported.

With the USING DESCRIPTOR :sqlda_struct option, the values of the program variables are substituted for parameter markers in the prepared statement. The program variables are addressed by corresponding sqldata entries in the SQLDA data structure. (The sqldata field is part of the sqlvar field.)

If the prepared statement contains parameter markers, the EXECUTE statement must include either the USING :hvar option with the same number of host variables in the same order as in the prepared statement or the USING DESCRIPTOR :sqlda_struct option that identifies the SQLDA data structure already populated by the application.

Also, the number of parameter markers in the prepared statement must match the number of sqldata entries (USING DESCRIPTOR :sqlda_struct) or host variables (USING :hvar).

Examples

EXEC SQL BEGIN DECLARE SECTION;

char   stmtbuf[] = "INSERT INTO publishers VALUES (?, ?, ?, ?)";

int    pubid;

char   pubname[30];

char   city[30];

char   state[3];

EXEC SQL END DECLARE SECTION;

  

// Prompt the user for publication data //

printf("Enter publication ID number: ");

scanf("%d", pubid);

printf("Enter publication name: ");

scanf("%s", pubname);

printf("Enter city: ");

scanf("%s", city);

printf("Enter state: ");

scanf("%s", state);

  

EXEC SQL PREPARE stmt FROM :stmtbuf;

  

EXEC SQL EXECUTE stmt USING :pubid, :pubname, :city, :state;

  

See Also
EXECUTE IMMEDIATE PREPARE

  


(c) 1988-98 Microsoft Corporation. All Rights Reserved.