Oracle Guide

SQLAPI++ allows to seamlessly work with a variety of SQL database servers. It provides unified API to access any database, keeping your code portable. 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.

For complete information on using SQLAPI++ check out Getting Started and Documentation. This guide covers specific information related to working with Oracle server using SQLAPI++ library in the following areas:

Connecting to a database

To connect to a database you need to initialize a connection object. A connection object is represented by SAConnection class.

Minimum Version
SQLAPI++ library requires Oracle OCI version 8 or higher.

After the connection is created you need to call SAConnection::Connect method to establish connection with Oracle server:

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

sDBString

Any valid Oracle connection string. For example - a database alias name as it is specified in TNSNAMES.ORA file. Additional information about Oracle connection string available in Oracle Instant Client FAQ.

sUserID

A string containing a user name to use when establishing the connection. If sUserID parameter is empty, SQLAPI++ library requests Oracle external authentication.

sPassword

A string containing a password to use when establishing the connection.

eSAClient

Optional. One of the following values from SAClient_t enum:
  • SA_Oracle_Client Oracle 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_Oracle_Client constant before

For more details see Getting Started - 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 Oracle in the following way:

SA_ReadUncommittedREAD COMMITTED
SA_ReadCommittedREAD COMMITTED
SA_RepeatableReadSERIALIZABLE
SA_SerializableSERIALIZABLE

In addition to the SQL-92 levels, if you specify 'snapshot' isolation level, it will be mapped as: SA_Snapshot SERIALIZABLE.

For more details see SAConnection::setIsolationLevel.

Working with Long or Lob (CLob, BLob) data

When fetching data SQLAPI++ detects data types of the columns in the result set and maps those types to internal library types. The mapping determines which native APIs the library will use for fetching LOB data.

The table below shows how SQLAPI++ maps Oracle server data types to Long/Lob library types:

LONG RAWSA_dtLongBinary
LONGSA_dtLongChar
BLOB, BFILE)SA_dtBLob
CLOB, CFILESA_dtCLob

When binding input data from your program the reverse mapping is taking place. The SQLAPI++ data type you use for input markers determines what native API program types will be used for sending Long/Lob data to the server.

The table below shows how SQLAPI++ maps its internal library types to Oracle API data types:
SA_dtLongBinarySQLT_LBI
SA_dtLongCharSQLT_LNG
SA_dtBLobSQLT_BLOB
SA_dtCLobSQLT_CLOB

Binding Lob (CLob, BLob) data when working with Oracle server has a specific requirement – it is necessary for a name of bind variable to be the same as the column name it is associated with:

UPDATE TEST SET FBLOB = :fblob WHERE FKEY = 'KEY'

Therefore, it's impossible to bind Lob (CLob, BLob) data in Oracle database by position.

For additional information see Getting Started - Handle Long/CLob/BLob.

Returning output parameters

In Oracle output parameters are available immediately after calling SACommand::Execute.

SQLAPI++ library automatically creates SAParam object to represent function return value. You can refer to this SAParam object using SQLAPI++ predefined name "RETURN_VALUE".

For additional information see SACommand::Execute, SAParam object, Getting Started - Get Output Parameters.

Cancelling queries

Using SACommand::Cancel method you can cancel the following types of processing on a statement:

  • function running asynchronously on the statement
  • function running on the statement on another thread

SQLAPI++ calls OCIBreak function to cancel a query. To get more details see OCIBreak function description in native Oracle documentation.

For additional information see SACommand::Cancel.

Connection, command, parameter and field options

Server specific options can be applied at the API, connection, command, parameter or field levels.

We recommend you specify each option at the appropriate level, although it is possible to specify them at the parent object level as well. In that case the option affects all the child objects.

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

Connection level options may be specified in either SAPI object or SAConnection object. If specified in SAPI object an option affects all connections on that API.

Command level options may be specified in SAPI object, SAConnection object or SACommand object. If specified in a parent object an option affects all commands on that SAPI or SAConnection object.

Parameter level options may be specified in SAPI object, SAConnection object, SACommand object or SAParam object. If specified in a parent object an option affects all parameters on that SAPI, SAConnection or SACommand object.

Field related options may be specified in SAPI object, SAConnection object, SACommand object or SAField object. If specified in a parent object an option affects all fields on that SAPI , SAConnection or SACommand object.

Specific options applicable to Oracle:

OCI8.LIBS
Api Scope
Forces SQLAPI++ library to use specified OCI library.
Valid values: Any valid OCI library name list. Names separated by ';' on Windows or ':' on other operating systems
Default value:
  • Windows - "oci.dll"
  • Linux - "libclntsh.so"
Special values: "STATIC", forces using the linked OCI functions when the library is compiled with SA_STATIC_ORACLE build option.
UseUCS2
Api Scope
[OCI >= 9; UNICODE only] UNICODE version of the SQLAPI++ uses UCS2 client character set for Oracle OCI >= 9. This option allows to use pre-configured client character set with the UNICODE SQLAPI++ version.
Valid values: "No", "False" or "0"
NLS_CHAR
Api Scope
[OCI >= 9; non-UNICODE] This option allows to specify client character set for entire connection with non-UNICODE SQLAPI++ version.
Valid values: String containing Oracle character set name ("US7ASCII", "CL8MSWIN1251", "SF7DEC", etc.) or its numeric code ("1", "171", "21", etc.). See Oracle documentation for more details.
Default value: By default SQLAPI++ doesn't change Oracle settings for this option.
ConnectAs
Connection Scope
Forces SQLAPI++ to connect with SYSDBA or SYSOPER privileges.
Valid values: "SYSDBA" or "SYSOPER"
UseTimeStamp
Connection Scope
This option allows to disable the usage of the OCIDateTime. Useful when OCI version 8 and higher is used with an old Oracle server versions that don't support TimeStamp data type.
Valid values: "No", "False" or "0"
UseSessionPool
Connection Scope
Forces SQLAPI++ to use Oracle session pool feature.
Valid values: One-based index of the used session pool
Default value: "0" (no session pool is used)
UseSessionPool_Min
Connection Scope
Specifies min size of the session pool.
Valid values: String containing the min size of the pool
Default value: "10"
UseSessionPool_Max
Connection Scope
Specifies max size of the session pool.
Valid values: String containing the max size of the pool
Default value: "100"
UseSessionPool_Incr
Connection Scope
Specifies the session pool increment value.
Valid values: String containing the pool increment value
Default value: "10"
UseSessionPool_Timeout
Connection Scope
Specifies the session pool OCI_ATTR_SPOOL_TIMEOUT attribute value.
Valid values: String containing the timeout value
UseConnectionPool
Connection Scope
Forces SQLAPI++ to use Oracle connection pool feature.
Valid values: One-based index of the used connection pool
Default value: "0" (no connection pool is used)
UseConnectionPool_MinConn
Connection Scope
Specifies min size of the connection pool.
Valid values: String containing the min size of the pool
Default value: "10"
UseConnectionPool_MaxConn
Connection Scope
Specifies max size of the connection pool.
Valid values: String containing the max size of the pool
Default value: "100"
UseConnectionPool_ConnIncr
Connection Scope
Specifies connection pool increment value.
Valid values: String containing the pool increment value
Default value: "10"
APPNAME
Connection Scope
OCI_ATTR_CLIENT_IDENTIFIER is used to identify client connection.
Valid values: client application name string
Default value: none
OCI_ATTR_RECEIVE_TIMEOUT
OCI_ATTR_SEND_TIMEOUT
Connection Scope
Undocumented OCI attributes allow to specify connection socket timeouts.
Valid values: the string representing timeout value (in milliseconds)
Default value: none
Overload
Command Scope
It is used when SQLAPI++ tries to detect package method parameters. When SQLAPI++ enumerates the package methods it uses the method with the "Overload" number to describe the parameters.
Valid values: String containing an integer
Default value: "1"
PreFetchRows
Command Scope
Forces SQLAPI++ library to fetch rows in bulk, rather than retrieving records one by one.
Valid values: String containing number of rows in the fetch buffer
Default value: "1"
OCI_ATTR_PREFETCH_ROWS
OCI_ATTR_PREFETCH_MEMORY
Command Scope
This options sets the corresponding OCI statement attribute values.
Valid values: String representing an integer value. See Oracle documentation for more details.
Default value: By default SQLAPI++ doesn't change Oracle settings for these options.
UseDynamicCursor
Scrollable
Command Scope
Forces SQLAPI++ to use scrollable readonly cursor. Requires OCIStmtFetch2 API function.
Valid values: "True", "1"
Default value: "False"
OCI_ATTR_CHARSET_ID
Parameter/Field Scope
This option sets character set ID of the parameter or the field.
Valid values: String containing Oracle character set name ("US7ASCII", "CL8MSWIN1251", "SF7DEC", etc.) or its numeric code ("1", "171", "21", etc.). See Oracle documentation for more details.
Default value: By default SQLAPI++ doesn't change Oracle settings for this option.
OCI_ATTR_CHARSET_FORM
Parameter/Field Scope
This option sets the character set form of the parameter or the field.
Valid values: "SQLCS_IMPLICIT", "SQLCS_NCHAR". See Oracle documentation for more details.
Default value: By default SQLAPI++ doesn't change Oracle settings for this option.

For additional information see SAOptions::setOption.

Using native Oracle 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 Oracle. 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 Oracle API. Note that using appropriate type casting depends on an API (that generally mean that you have to explicitly check client version before casting, see SAConnection::ClientVersion method).

To use native API you need to add Oracle specific #include and cast the result of SAConnection::NativeAPI to class oraAPI:

#include "oraAPI.h"

IsaAPI *pApi = con.NativeAPI();
oraAPI *pNativeAPI = (oraAPI *)pApi;

To get more information about Oracle API functions see Oracle documentation.

For additional information see SAConnection::NativeAPI.

Getting native Oracle connection related handles

You have to use native API handles when you want to call specific Oracle API functions which are not directly supported by the library. API functions usually need to receive one or more active handles as parameters. 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.

To access native connection handles you need to add Oracle specific #include and cast the result to class oraConnectionHandles:

#include "oraAPI.h"

saConnectionHandles *pHandles = con.NativeHandles();
oraConnectionHandles *pNativeHandles = (oraConnectionHandles*)pHandles;

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

For additional information see SAConnection::NativeHandles.

Getting native Oracle command related handles

You have to use native API handles when you want to call specific Oracle API functions which are not directly supported by the library. API functions usually need to receive one or more active handles as parameters. 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.

To access native command handles you need to add Oracle specific #include and cast the result to class oraCommandHandles:

#include "oraAPI.h"

saCommandHandles *pHandles = cmd.NativeHandles();
oraCommandHandles *pNativeHandles = (oraCommandHandles*)pHandles;

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

For additional information see SACommand::NativeHandles.

Error handling

When an error occurs when executing a SQL statement SQLAPI++ library throws an exception of type SAException and SAException::ErrPos method returns error position in the SQL statement.

In Oracle server SAException::ErrPos method returns parse error offset.

For additional information see Getting Started - Error Handling, SAException object.