InterBase Guide

SQLAPI++ allows to work with a number of SQL database servers. It provides common mechanisms to access database, and as a general rule they work for any database server. But each server has some specific features which a developer has to know in order to leverage server's unique features and avoid potential errors.

This page collects all specific information that concerns working with InterBase server using SQLAPI++ Library. Full information about using SQLAPI++ see in How To and Documentation.

Available topics:

Connecting to a database

To connect to a database you should create a connection object and then connect it. A connection object is represented by SAConnection class. After the connection is created you need to connect it to InterBase server using SAConnection::Connect method

void Connect(
    const SAString &sDBString,
    const SAString &sUserID,
    const SAString &sPassword,
    SAClient_t eSAClient = SA_Client_NotSpecified);

with the following parameters:

sDBString
  • For local InterBase databases, this can be a file name.
  • To connect to an InterBase database on a remote server using TCP/IP the syntax is <server_name>:<filename>
  • To connect to an InterBase database on a remote server using NetBEUI, the syntax is \\<server_name>\<filename>
  • To connect to an InterBase database on a remote server using SPX, the syntax is <server_name>@<filename>
sUserIDA string containing a user name to use when establishing the connection.
sPasswordA string containing a password to use when establishing the connection.
eSAClientOptional. One of the following values from SAClient_t enum:
  • SA_InterBase_Client InterBase client.
  • SA_Client_NotSpecified Used by default if eSAClient parameter is omitted. You can use this default value only if you have SAConnection::setAPI method with SAPI object initialized with SA_InterBase_Client constant before.

The SQLAPI++ Library requires Informix CLI version 2.x or higher.

For more details see How To - Connect to database, SAConnection object, SAConnection::Connect.

Transaction isolation levels

SQL-92 defines four isolation levels, all of which are supported by SQLAPI++:

  • Read uncommitted (the lowest level where transactions are isolated just enough to ensure that physically corrupt data is not read)
  • Read committed
  • Repeatable read
  • Serializable (the highest level, where transactions are completely isolated from one another)

SQLAPI++ maps different isolation levels on InterBase server in the following way:

SA_ReadUncommitted = isc_tpb_read_committed, isc_tpb_rec_version
SA_ReadCommitted = isc_tpb_read_committed, isc_tpb_no_rec_version
SA_RepeatableRead = isc_tpb_consistency
SA_Serializable = isc_tpb_concurrency

For more details see SAConnection::setIsolationLevel.

Working with Long or Lob (CLob, BLob) data

SQLAPI++ supports four types for working with Long or Lob (CLob, BLob) data:

NameC++ Enum
LongBinarySA_dtLongBinary
LongCharSA_dtLongChar
BLob (Binary Large object)SA_dtBLob
CLob (Character Large object)SA_dtCLob

The table below shows how SQLAPI++ data types correspond with servers original data types:

SA_dtLongBinary <=> BLOB, subtype 0
SA_dtLongChar <=> BLOB, subtype 1
SA_dtBLob => BLOB, subtype 0
SA_dtCLob => BLOB, subtype 1

For more details see How To - Working with Long or Lob (CLob, BLob) data.

Returning output parameters

If InterBase stored procedure returns only one row of output parameters (the most common case), you can get output parameters' values immediately after calling SACommand::Execute using appropriate SAParam objects.

In InterBase stored procedures can also return several rows of output parameters. In this case you should perform a select from a procedure to return them as result set.

For more details see SACommand::Execute, SAParam object, How To - Get output parameters.

Cancelling queries

InterBase does not support cancelling queries.

For more details see SACommand::Cancel.

Connection, command, parameter and field options

A server specific option can relate to a connection, command, parameter or field. We recommend you specify each option in an appropriate object, although it is possible to specify them in the parental object as well. In that case the option affects all the child objects.

An API related option must be specified in SAPI object. If an internal SAPI object used for the DBMS API initialization (implicit DBMS API initialization, see SAConnection::Connect method) the related DBMS specific options taken from initial connection object.

A connection related option may be specified in either SAPI object or SAConnection object. If it is specified in SAPI object it affects all the connections on that API.

A command related option may be specified in SAPI object, SAConnection object or SACommand object. If it is specified in a parent object it affects all the commands on that SAPI, SAConnection objects.

A parameter related option may be specified in SAPI object, SAConnection object, SACommand object or SAParam object. If it is specified in a parent object it affects all the parameters on that SAPI, SAConnection, SACommand objects.

A field related option may be specified in SAPI object, SAConnection object, SACommand object or SAField object. If it is specified in a parent object it affects all the fields on that on that SAPI, SAConnection, SACommand objects.

Specific options for InterBase server:

Option name / ScopeDescription

IBASE.LIBS

API related. Should be specified before the API is initialized.

Forces SQLAPI++ Library to use specified InterBase/Firebird client library.

Valid values: Any valid InterBase client library name list. Names separated by ';' on Windows or ':' on other operating systems

Default value:

  • Windows - "gds32.dll;fbclient.dll"
  • Linux - "libgds.so:libfbclient.so"

isc_dpb_lc_ctype

Connection related. Should be specified before actual connection is made.

Specifies the character set to be utilized. For more information see InterBase documentation.

Valid values: String containing character set name, see InterBase documentation

Default value: see InterBase documentation

isc_dpb_sql_role_name

Connection related. Should be specified before actual connection is made.

Declares role name that should used for connection. For more information see InterBase documentation.

Valid values: see InterBase documentation

Default value: see InterBase documentation

isc_dpb_num_buffers

Connection related. Should be specified before actual connection is made.

Declares the number of database cache buffers to allocate for use with the database. For more information see InterBase documentation.

Valid values: String represents numeric values 10-255, see InterBase documentation

Default value: "75", see InterBase documentation

CommitRetaining

Connection related. Should be specified before actual connection is made.

Determines which function (isc_commit_transaction() or isc_commit_retaining()) SQLAPI++ calls to commit transactions. isc_commit_transaction() writes transaction changes permanently to a database, closes the result set associated with the transaction, and frees system resources assigned to the transaction for other uses. Active result sets are not preserved. isc_commit_retaining() writes all pending changes to the database, ends the current transaction without closing its record stream and cursors and without freeing its system resources, then starts a new transaction and assigns the existing record streams and system resources to the new transaction. Active result sets are preserved. For more information see InterBase documentation (isc_commit_retaining() and isc_commit_transaction() functions).

Valid values: "true" to force SQLAPI++ to call isc_commit_retaining() function, "false" to force SQLAPI++ to call isc_commit_transaction() function

Default value: "false". SQLAPI++ uses isc_commit_transaction() function by default

TPB_LockResolution

Connection related. Should be specified before actual connection is made.

Describes what happens if a transaction encounters an access conflict during a write operation (update and delete operations on existing rows).

Valid values: "isc_tpb_wait" (specifies that the transaction should wait until locked resources are released; once the resources are released, the transaction retries its operation), "isc_tpb_nowait" (specifies that the transaction should return a lock conflict error without waiting for locks to be released)

Default value: By default SQLAPI++ doesn't change InterBase settings for this option. See InterBase documentation for details

TPB_AccessMode

Connection related. Should be specified before actual connection is made.

Describes the actions a transaction can perform against a table.

Valid values: "isc_tpb_write" (enables a transaction to read data from a table and write data to it), "isc_tpb_read" (restricts table access to read only)

Default value: By default SQLAPI++ doesn't change InterBase settings for this option. See InterBase documentation for details

SQLDialect

Command related.

Declares the SQL Dialect for database access.

Valid values: see InterBase documentation

Default value: "3"

For more details see SAConnection::setOption, SACommand::setOption, SAField::setOption, SAParam::setOption.

Getting native InterBase API

You can call client specific API functions which are not directly supported by SQLAPI++ Library. SAConnection::NativeAPI method returns a pointer to the set of native API functions available for InterBase. To use the database API directly you have to downcast this IsaAPI pointer to the appropriate type and use its implementation-specific members. The following example shows what type cast you have to make and what additional header file you have to include to work with InterBase API.

Cast the result to class ibAPI:

#include "ibAPI.h"
 
IsaAPI *pResult = con.NativeAPI();
ibAPI *p_ibAPI = (ibAPI *)pResult;

To get more information about DBMS API functions see this DBMS specific documentation.

For more details see SAConnection::NativeAPI.

Getting native InterBase connection related handles

You have to use native API handles when you want to call specific InterBase API functions which are not directly supported by the Library. API functions usually need to receive one or more active handles as a parameter(s). SAConnection::NativeHandles method returns a pointer to the set of native API connection related handles. To use API handles directly you have to downcast saConnectionHandles pointer to the appropriate type and use its implementation-specific members. The following table shows what type cast you have to make and what additional header file you have to include to work with specific InterBase API.

Cast the result to class ibConnectionHandles:

#include "ibAPI.h"
 
saConnectionHandles *pResult = con.NativeHandles();
ibConnectionHandles *p_ibCH = (ibConnectionHandles*)pResult;

To get more information about DBMS API functions and handles see this DBMS specific documentation.

For more details see SAConnection::NativeHandles.

Getting native InterBase command related handles

You have to use native API handles when you want to call specific InterBase API functions which are not directly supported by the Library. API functions usually need to receive one or more active handles as a parameter(s). SACommand::NativeHandles method returns a pointer to the set of native API command related handles. To use API handles directly you have to downcast saCommandHandles pointer to the appropriate type and use its implementation-specific members. The following example shows what type cast you have to make and what additional header file you have to include to work with specific InterBase API.

Cast the result to class ibCommandHandles:

#include "ibAPI.h"
 
saCommandHandles *pResult = cmd.NativeHandles();
ibCommandHandles *p_ibCH = (ibCommandHandles*)pResult;

To get more information about DBMS API functions and handles see this DBMS specific documentation.

For more details see SACommand::NativeHandles.

Error handling

When an error occurs inside SQLAPI++ Library it throws an exception of type SAException.

SAException::ErrPos method gets an error position in SQL statement. In InterBase server SAException::ErrPos method returns -1 because InterBase does not support this function.

For more details see How To - Error handling, SAException object.

Special header files - Compile time

The header files are in the include subdirectory of SQLAPI++ distributions:

  • #include "SQLAPI.h" - main header, should be used whenever SQLAPI++ is used
  • #include "ibAPI.h" - InterBase API, should be included if direct InterBase API calls are required

For more details see Documentation - Instructions for Compiling and Linking Applications with SQLAPI++