Using isc_dsql_prepare() and isc_dsql_execute()
Go Up to Method 1: Non-query Statements Without Parameters
To execute a statement string several times, use isc_dsql_allocate_statement(), isc_dsql_prepare(), and isc_dsql_execute():
- Elicit a statement string from the user or create one that contains the SQL statement to be processed. For example, the following statement creates a SQL statement string:
char *str = "UPDATE DEPARTMENT SET BUDGET = BUDGET * 1.05";
- Declare and initialize a SQL statement handle, then allocate it with
isc_dsql_allocate_statement():isc_stmt_handle stmt; /* Declare a statement handle. */ stmt = NULL; /* Set handle to NULL before allocation. */ . . . isc_dsql_allocate_statement(status_vector, &db1, &stmt);
- Parse the statement string with
isc_dsql_prepare(). This sets the statement handle (stmt) to refer to the parsed format. The statement handle is used in subsequent calls toisc_dsql_execute():isc_dsql_prepare(status_vector, &trans, &stmt, 0, str, 1, NULL);
isc_dsql_prepare()also accepts string literals. For example,
isc_dsql_prepare(status_vector, &trans, &stmt, 0, "UPDATE DEPARTMENT SET BUDGET = BUDGET * 1.05", 1, NULL);
- Execute the named statement string using
isc_dsql_execute(). For example, the following statement executes a statement string namedstmt:isc_dsql_execute(status_vector, &trans, &stmt, 1, NULL);
Once a statement string is prepared, it can be executed as many times as required in an application.