Method 1: Non-query Statements Without Parameters
From InterBase
Go Up to DSQL Programming Methods
There are two ways to process a SQL statement string containing a non-query statement without placeholder parameters:
- Use
isc_dsql_execute_immediate()
to prepare and execute the string a single time. - Use
isc_dsql_allocate_statement()
to allocate a statement string for the statement to execute,isc_dsql_prepare()
to parse the statement for execution and assign it a name, then useisc_dsql_execute()
to carry out the statement’s actions as many times as required in an application.
Using isc_dsql_execute_immediate()
- To execute a statement string a single time, use
isc_dsql_execute_immediate()
: - 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";
- Parse and execute the statement string using
isc_dsql_execute_immediate
():isc_dsql_execute_immediate(status_vector, &db1, &trans, 0, str, 1, NULL);
- Note:
isc_dsql_execute_immediate()
also accepts string literals. For example, isc_dsql_execute_immediate(status_vector, &db1, &trans, 0,"UPDATE DEPARTMENT SET BUDGET = BUDGET * 1.05", 1, NULL);
For the complete syntax of isc_dsq_execute_immediate()
and an explanation of its parameters, see API Function Reference.
Using isc_dsql_prepare() and isc_dsql_execute()
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
:Once a statement string is prepared, it can be executed as many times as required in an application.isc_dsql_execute(status_vector, &trans, &stmt, 1, NULL);