Handling Transactions

From InterBase

Go Up to DSQL API Limitations

InterBase requires all transaction handles to be declared when an application is compiled. Once fixed at compile time, transaction handles cannot be changed at runtime, nor can new handles be declared dynamically at runtime. Most API functions that process SQL statements at runtime, such as isc_dsql_describe(), isc_dsql_describe_bind(), isc_dsql_execute(), isc_dsql_execute2(), ­isc_dsql_execute_immediate(), isc_dsql_exec_immed2(), and ­isc_dsql_prepare(), support the inclusion of a transaction handle parameter. The SQL statements processed by these functions cannot pass transaction handles, even if the SQL syntax for the statement permits the use of a ­TRANSACTION clause.

Before a transaction handle can be used, it must be declared and initialized to zero. The following code declares, initializes, and uses a transaction handle in an API call that allocates and prepares a SQL statement for execution:

#include <ibase.h>
. . .
isc_tr_handle trans; /* Declare a transaction handle. */
isc_stmt_handle stmt; /* Declare a statement handle. */
char *sql_stmt = "SELECT * FROM EMPLOYEE";
isc_db_handle db1;
ISC_STATUS status_vector[20];
. . .
trans = 0L; /* Initialize the transaction handle to zero. */
stmt = NULL; /* Set handle to NULL before allocation. */
/* This code assumes that a database attachment is made,
 * and a transaction is started here. */
. . .
/* Allocate the SQL statement handle. */
isc_dsql_allocate_statement(status_vector, &db1, &stmt);
/* Prepare the statement for execution. */
isc_dsql_prepare(status_vector, &trans, &stmt, 0, sql_stmt, 1, NULL);
The SQL SET TRANSACTION statement cannot be prepared with ­isc_dsql_prepare(), but it can be processed with ­isc_dsql_execute_immediate() if:
  1. Previous transactions are first committed or rolled back.
  2. The transaction handle is set to NULL.

For more information about using SQL statements, see the Embedded SQL Guide. For more information about SQL statement syntax, see the Language Reference Guide.

Advance To: