The SOCI Oracle backend is currently supported for use with Oracle 10g.
Older versions of Oracle may work as well, but they have not been tested by the SOCI team.
Oracle version | Operating System | Compiler |
---|---|---|
10.1.0 | Linux i686 2.6.10-gentoo-r6 | g++ 3.4.5 |
10.1.0 | Linux i686 2.4.21 (RedHat family) | g++ 3.2.3 |
10.2.0 | Windows XP | Visual C++ 8.0 Professional |
The SOCI Oracle backend requires Oracle's libclntsh
client library.
To establish a connection to an Oracle database, create a Session object using the oracle backend factory together with a connection string:
BackEndFactory const &backEnd = oracle; Session sql(oracle, "service=orcl user=scott password=tiger");
The set of parameters used in the connection string for Oracle is:
All 3 of these parameters have to be provided as part of the connection string.
Once you have created a Session
object as shown above, you can use it to access the database, for example:
int count; sql << "select count(*) from user_tables", into(count);
(See the SOCI basics and exchanging data documentation for general information on using the Session
class.)
The Oracle backend supports the use of the SOCI Row
class, which facilitates retrieval of data whose type is not known at compile time.
When calling Row::get<T>()
, the type you should pass as T depends upon the underlying database type.
For the Oracle backend, this type mapping is:
Oracle Data Type | SOCI Data Type | Row::get<T> specializations |
---|---|---|
number (where scale > 0) | eDouble |
double |
number (where scale = 0 and precision < std::numeric_limits<int>::digits10) |
eInteger |
int |
number | eUnsignedLong |
unsigned long |
char, varchar, varchar2 | eString |
std::string |
date | eDate |
std::tm
|
(See the dynamic resultset binding documentation for general information on using the Row
class.)
In addition to binding by position, the Oracle backend supports binding by name, via an overload of the use()
function:
int id = 7; sql << "select name from person where id = :id", use(id, "id")
SOCI's use of ':' to indicate a value to be bound within a SQL string is consistant with the underlying Oracle client library syntax.
The Oracle backend has full support for SOCI's bulk operations interface.
Transactions are also fully supported by the Oracle backend.
The Oracle backend supports working with data stored in columns of type Blob, via SOCI's BLOB
class.
Oracle rowid's are accessible via SOCI's RowID
class.
The Oracle backend supports selecting into objects of type Statement
, so that you may work with nested sql statements and PL/SQL cursors:
Statement stInner(sql); Statement stOuter = (sql.prepare << "select cursor(select name from person order by id)" " from person where id = 1", into(stInner)); stInner.exchange(into(name)); stOuter.execute(); stOuter.fetch(); while (stInner.fetch()) std::cout << name << '\n';
Oracle stored procedures can be executed by using SOCI's Procedure
class.
SOCI provides access to underlying datbabase APIs via several getBackEnd() functions, as described in the beyond SOCI documentation.
The Oracle backend provides the following concrete classes for navite API access:
Accessor Function | Concrete Class |
---|---|
SessionBackEnd* Session::getBackEnd() |
OracleSessionBackEnd |
StatementBackEnd* Statement::getBackEnd() |
OracleStatementBackEnd |
BLOBBackEnd* BLOB::getBackEnd() |
OracleBLOBBackEnd |
RowIDBackEnd* RowID::getBackEnd() |
OracleRowIDBackEnd |
The Oracle backend can throw instances of class OracleSOCIError
,
which is publicly derived from SOCIError
and has an
additional public errNum_
member containing the Oracle error code:
int main() { try { // regular code } catch (OracleSOCIError const &e) { cerr << "Oracle error: " << e.errNum_ << " " << e.what() << endl; } catch (exception const &e) { cerr << "Some other error: " << e.what() << endl; } }
Copyright © 2004-2006 Maciej Sobczak, Stephen Hutton