isc_dsql_execute_immediate()
Go Up to API Function Reference
Prepares and executes just once a DSQL statement that does not return data. There is a special case of isc_dsql_execute_immediate()
for creating databases. For more information about creating and populating the XSQLDA
, see Understanding the XSQLDA. To check for an InterBase error, examine the first two elements of the status vector directly. For more information about examining the status vector, see Handling Error Conditions.
Syntax
ISC_STATUS isc_dsql_execute_immediate(
ISC_STATUS *status_vector,
isc_db_handle *db_handle,
isc_tr_handle *trans_handle,
unsigned short length,
char *statement,
unsigned short dialect,
XSQLDA *xsqlda);
- Note: In the special case where the statement is
CREATE DATABASE
, there is no transaction, sodb_handle
andtrans_handle
must be pointers to handles whose value isNULL
. Whenisc_dsql_execute_immediate()
returns,db_handle
is a valid handle, just as though you had made a call toisc_attach_database()
.
Parameter | Type | Description |
---|---|---|
|
|
Pointer to the error status vector |
|
|
|
|
|
|
|
|
Length of the DSQL statement in bytes; set to 0 in C programs to indicate a null-terminated string |
|
|
DSQL string to be executed |
|
|
|
|
|
Pointer to an optional, previously allocated |
Description
isc_dsql_execute_immediate()
prepares the DSQL statement specified in <statement>, executes it once, and discards it. The statement must not be one that returns data (that is, it must not be a SELECT
or EXECUTE PROCEDURE
statement).
If <statement> requires input parameter values (that is, if it contains parameter markers), these values must be supplied in the input XSQLDA
, xsqlda
.
To create a database using isc_dsql_execute_immediate()
, supply a CREATE DATABASE
statement and have db_handle
and trans_handle
point to handles with a NULL value.
- Tip: If
statement
returns data, or if it needs to be executed more than once, useisc_dsql_prepare
() andisc_dsql_execute()
(orisc_dsql_execute2()
) instead ofisc_dsql_execute_immediate()
. - Note: You must call
isc_dsql_execute_immediate()
rather thanisc_dsql_prepare()
andisc_dsql_execute()
forCREATE DATABASE
orSET TRANSACTION
. To start a transaction, you also have the option of usingisc_start_transaction()
.
Examples
The following program fragment calls isc_dsql_execute_immediate()
to perform an insert:
#include <ibase.h> ISC_STATUS status_vector[20]; char *insert_stmt = "INSERT INTO CUSTOMER(CUSTNAME, BAL, CUSTNO) VALUES("John Smith", 299.0, 5050)"; isc_dsql_execute_immediate( status_vector, &database_handle, /* Set in previous isc_attach_database() call. */ &tr_handle, /* Set in previous isc_start_transaction() call. */ 0, insert_stmt, 1, NULL); if (status_vector[0] == 1 && status_vector[1]) { /* Process error. */ isc_print_status(status_vector); return(1); }
The following C/C++ code fragment uses isc_dsql_execute_immediate()
to create a database and return a handle to the new database:
#include <ibase.h> ISC_STATUS status_vector[20]; char *statement = "CREATE DATABASE 'C:/INVENTORY.IB' PAGE_SIZE 4096 USER 'SYSDBA' PASSWORD 'masterkey'"; isc_db_handle db_handle = NULL; isc_tr_handle dummy_handle = NULL; isc_dsql_execute_immediate( status_vector, &db_handle, &dummy_handle, 0, statement, 1, NULL); if (status_vector[0] == 1 && status_vector[1]) { /* Process error. */ isc_print_status(status_vector); return(1); }
Return value
isc_dsql_execute_immediate()
returns the second element of the status vector. Zero indicates success. A nonzero value indicates an error. For InterBase errors, the first element of the status vector is set to 1, and the second element is set to isc_bad_db_handle
, isc_bad_trans_handle
, or another InterBase error code.
To check for an InterBase error, examine the first two elements of the status vector directly. For more information about examining the status vector, see Handling Error Conditions.