Home How To Online Documentation Support Download Order
 

 

 


SACommand
SAConnection
SAException
SAField
SAParam
SAString
SADateTime
SANumeric

Enums and Typedefs


Server Specific Guide

Oracle

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 Oracle server using SQLAPI++ Library. Full information about using SQLAPI++ see in How To and Online Documentation.

Available topics:

Connecting to a database

Transaction isolation levels

Working with Long or Lob(CLob, BLob) data

Returning output parameters

Cancelling queries

Connection, command, parameter and field options

Getting native Oracle API

Getting native Oracle connection related handles

Getting native Oracle command related handles

Error handling

Special header files - Compile time

 

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 Oracle 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.    The database name as it is specified in TNSNAMES.ORA file. An additional information about Oracle connection string available with Oracle Instant Client FAQ (<hostname>[:<port>][/<service_name>] ).
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 eSAClientparameter is omitted.  You can use this default value only if you have call SAConnection::setClient method with SA_Oracle_Client constant before.

The SQLAPI++ Library requires OCI version 7.3 or higher. The Library tries to connect to Oracle using new OCI8 (Oracle 8 and higher) first. If it fails it tries to connect using OCI7. If you want to use directly OCI7 or OCI8 API you should set "UseAPI" connection option before specifying Oracle client or connecting to database.

For more details see How To - Connecting to databases, SAConnection object, SAConnection::Connect, SAConnection::setOption

 

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 server in the following way:

      SA_ReadUncommitted = 'READ COMMITTED'
      SA_ReadCommitted = 'READ COMMITTED'
      SA_RepeatableRead = 'SERIALIZABLE'
      SA_Serializable = 'SERIALIZABLE'

For more details see SAConnection::setIsolationLevel.

 

Working with Long or Lob(CLob, BLob) data

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

Name C enum constant
LongBinary SA_dtLongBinary
LongChar SA_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:

When using new OCI (Oracle 8 and higher):

SA_dtLongBinary <= > LONG RAW
SA_dtLongChar <= > LONG
SA_dtBLob <= > BLOB, FILE
SA_dtCLob <= > CLOB

When using OCI7:

SA_dtLongBinary <= > LONG RAW
SA_dtLongChar <= > LONG
SA_dtBLob = > LONG RAW
SA_dtCLob = > LONG

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

2. Binding Lob(CLob, BLob) data when working with Oracle server has some differences from others (see How To - Binding input parameters). It's necessary for a name of bind variable to be the same as the column name it associated with.

Ex.:     Update TEST set FBLOB = :fblob where FKEY = 'KEY'

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

For more details see How To - Binding input parameters.

 

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 more details see SACommand::Execute, SAParam object, How To - Returning Output Parameters.

 

Cancelling queries

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

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

SQLAPI++ calls obreak function with Oracle 7 (OCI7) to cancel a query. To get more details see obreak function description in Oracle documentation.

SQLAPI++ calls OCIBreak function with Oracle 8 (OCI8) to cancel a query. To get more details see OCIBreak function description in Oracle documentation.

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.

A connection related option must be specified in a  SAConnection object.

A command related option may be specified in either SAConnection object or SACommand object. If it is specified in SAConnection object it affects all the commands on that connection.

A parameter related option may be specified in SAConnection object, SACommand object or SAParam object. If it is specified in SAConnection object it affects all the commands and therefore all the parameters on that connection. If it is specified in SACommand object it affects all the parameters on that command.

A field related option may be specified in SAConnection object, SACommand object or SAField object. If it is specified in SAConnection object it affects all the commands and therefore all the fields on that connection. If it is specified in SACommand object it affects all the fields on that command.

Specific options for Oracle:

Option name / Scope

Description

UseAPI

Connection related.

Forces SQLAPI++ Library to use directly OCI7 or new OCI8 (Oracle 8 and higher) API.

Valid values: "OCI7", "OCI8" and "OCIAuto".
Default value: "OCIAuto". In this case SQLAPI++ tries to connect to Oracle using new OCI8 first. If it fails it tries to connect using OCI7.

OCI8.LIBS

Connection related. Should be specified before the first connection is made.
Forces SQLAPI++ Library to use specified OCI library.

Valid values : Any valid OCI8 library name list. Names separated by ';' on Windows or ':' on other OS.
Default value: Windows - "oci.dll", Linux -  "libclntsh.so".

PreFetchRows

Command related. Should be specified before command execution.

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".

ConnectAs

Connection related (OCI8).

Forces SQLAPI++ to connect with SYSDBA or SYSOPER privileges.

Valid values: "SYSDBA" or "SYSOPER"

UseConnectionPool

Connection related (OCI8).

Forces SQLAPI++ to use Oracle connection pool feature.

Valid values: One-based index of the used connection pool.
Default value: "0" (no connection pool used).

UseConnectionPool_MinConn

Connection related (OCI8).

Minimal size of the connection pool.

Valid values: String containing the minimal size of the pool.
Default value: "10".

UseConnectionPool_MaxConn

Connection related (OCI8).

Maximal size of the connection pool.

Valid values: String containing the minimal size of the pool.
Default value: "100".

UseConnectionPool_ConnIncr

Connection related (OCI8).

The connection pool increment value.

Valid values: String containing the pool increment value.
Default value: "10".

UseUCS2

Connection related
(OCI >= 9,  UNICODE).

The 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

Connection related
(OCI >= 9,  non UNICODE).

This option allows to specify client character set for entire connection with the 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. By default SQLAPI++ doesn't change Oracle settings for this option. See Oracle documentation for details.

UseTimeStamp

Connection related
(OCI8).

This option allows to disable the using of the OCIDateTime.  Useful when OCI version 8 and higher is used with old Oracle server versions don't support TimeStamp data type.

Valid values: "No", "False" or "0".

APPNAME

Connection related
(OCI8)

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 related
(OCI8)

Undocumented OCI attributes allow to specify connection socket timeouts.

Valid values: timeout value (in milliseconds).
Default value :none.

Overload

Command related.

It's used when SQLAPI++ tries to detect package method parameters. When SQLAPI++ enumerates the package methods it uses the method with "Overload" number to describe the parameters.

Valid values: String containing a decimal number. Default value: "1".

UseDynamicCursor
or
Scrollable

Command related. Should be specified before describing parameters or command execution.
Forces SQLAPI++ to use scrollable readonly cursor. Requires OCIStmtFetch2 API function.

Valid values: "True", "1". Default value: "false".

OCI_ATTR_CHARSET_ID

Parameter related. Should be specified before command execution.

This option sets character set ID of the parameter.

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.
By default SQLAPI++ doesn't change Oracle settings for this option. See Oracle documentation for details.

OCI_ATTR_CHARSET_FORM

Parameter related. Should be specified before command execution.

 

This option sets the character set form of the parameter.

Valid values: "SQLCS_IMPLICIT", "SQLCS_NCHAR". See Oracle documentation for more details. 
By default SQLAPI++ doesn't change Oracle settings for this option. See Oracle documentation for details.

OCI_ATTR_CHARSET_ID

Field related. Should be specified before fetching.

This option sets character set ID of 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.
By default SQLAPI++ doesn't change Oracle settings for this option. See Oracle documentation for details.

OCI_ATTR_CHARSET_FORM

Field related. Should be specified before fetching.

 

This option sets the character set form of the field.

Valid values: "SQLCS_IMPLICIT", "SQLCS_NCHAR". See Oracle documentation for more details. 
By default SQLAPI++ doesn't change Oracle settings for this option. See Oracle documentation for details.

OCI_ATTR_PREFETCH_ROWS
OCI_ATTR_PREFETCH_MEMORY

Command related. Should be specified before describing parameters or command execution.

 

This options set the corresponding OCI statement attribute values.

Valid values: Any integer value. See Oracle documentation for more details. 
By default SQLAPI++ doesn't change Oracle settings for these options. See Oracle documentation for details.

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

 

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

DBMS client

Type casting

Additional
include file

Oracle 7 (OCI7)

Cast the result to class ora7API:

saAPI *pResult = con.NativeAPI();
ora7API *p_ora7API = (ora7API *)pResult;

#include <ora7API.h>

Oracle 8 and higher (OCI8)

Cast the result to class ora8API:

saAPI *pResult = con.NativeAPI();
ora8API *p_ora8API = (ora8API *)pResult;

#include <oraAPI.h>

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

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

DBMS client

Type casting

Oracle 7 (OCI7)

Cast the result to class ora7ConnectionHandles:

#include <ora7API.h>

saConnectionHandles *pResult = con.NativeHandles();
ora7ConnectionHandles *p_ora7CH =
                                (ora7ConnectionHandles *)pResult;

Available handles:

  • Lda_Def  m_lda; 
  • ub1  m_hda[512];

Oracle 8 and higher(OCI8)

Cast the result to class ora8ConnectionHandles:

#include <oraAPI.h>

saConnectionHandles *pResult = con.NativeHandles();
ora8ConnectionHandles *p_ora8CH =
                                (ora8ConnectionHandles *)pResult;

Available handles:

  • OCIEnv *m_pOCIEnv;
  • OCIError *m_pOCIError;
  • OCISvcCtx *m_pOCISvcCtx;
  • OCIServer *m_pOCIServer;
  • OCISession *m_pOCISession;

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

For more details 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 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 table shows what type cast you have to make and what additional header file you have to include to work with specific Oracle API. Note that using appropriate type casting depends on an API version (that generally mean that you have to explicitly check client version before casting, see SAConnection::ClientVersion method).

DBMS client

Type casting

Oracle 7 (OCI7)

Cast the result to class ora7CommandHandles:

#include <ora7API.h>

saCommandHandles *pResult = cmd.NativeHandles();
ora7CommandHandles *p_ora7CH =
                                (ora7CommandHandles *)pResult;

Available handles:

  • Cda_Def  m_cda;

Oracle 8 and higher(OCI8)

Cast the result to class ora8CommandHandles:

#include <oraAPI.h>

saCommandHandles *pResult = cmd.NativeHandles();
ora8CommandHandles *p_ora8CH =
                                (ora8CommandHandles *)pResult;

Available handles:

  • OCIStmt *m_pOCIStmt;
  • OCIError *m_pOCIError;

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 Oracle server SAException::ErrPos method returns parse error offset.

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 <ora7API.h>, <oraAPI.h> - Oracle API, should be included if direct OCI calls are required.

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

 

Problems and Questions

If you haven't found the answer to you questions or have some problems on using the Library, please, send e-mail to howto@sqlapi.com.