Argument |
OCI Type |
Description |
\c Type::Binary |
\c SQLT_BIN |
For use with \c BLOB columns, for example. |
\c Type::String |
\c SQLT_STR |
For use with string data, \c VARCHAR, \c CHAR, \c CLOB columns, etc |
\c Type::Int |
\c SQLT_INT or \c SQLT_STR |
if the int > 32-bits = \c SQLT_STR, <= 32-bit int = \c SQLT_INT |
\c Type::Boolean |
\c SQLT_INT |
True is bound as 1, False as 0 |
\c Type::Float |
\c SQLT_BDOUBLE |
For use with \c FLOAT, \c BINARY_FLOAT, \c BINARY_DOUBLE columns, etc |
\c Type::Date |
\c SQLT_TIMESTAMP |
For use with \c DATE, \c TIMESTAMP, etc columns |
Wrapped \c Type::Hash and \c Type::List |
\c SQLT_NTY |
For use with @ref named_types |
@subsection binding_by_placeholder Binding by Placeholder
Argument |
OCI Type |
Description |
\c Type::Binary |
\c SQLT_BIN |
For retrieving \c RAW data up to 65531 bytes in size. |
\c SQL::BLOB |
\c SQLT_BLOB |
For retrieving \c BLOB data. The \c LOB handle is used to read the entire \c BLOB content into a binary object. |
\c SQL::CLOB |
\c SQLT_CLOB |
For retrieving \c CLOB data. The \c LOB handle is used to read the entire \c CLOB content into a Qore string. |
\c SQL::VARCHAR |
\c SQLT_STR |
For retrieving character data (\c VARCHAR2, etc). To specify a buffer size larger than 512 bytes, simply use the size in bytes as the argument. See @ref string_sizes |
\c Type::Int |
\c SQLT_INT |
For retrieving integer numeric data up to 32 bits (for larger numbers or for non-integer numbers use \c SQL::VARCHAR or \c Type::Float. |
\c Type::Float |
\c SQLT_BDOUBLE |
For retrieving data in 64-bit floating point format. |
\c Type::Date |
\c SQLT_TIMESTAMP |
For retrieving dates and times. |
\c Type::Hash |
\c SQLT_RSET |
For retrieving result sets from a stored procedure that returns a cursor. |
Wrapped \c Type::Hash and \c Type::List |
\c SQLT_NTY |
For use with @ref named_types |
@subsection default_oracle_to_qore_mapping Default Oracle to Qore Mappings
Oracle Column Type |
Qore Type |
Notes |
\c REAL, \c FLOAT, \c DOUBLE \c PRECISION, \c BINARY_FLOAT, \c BINARY_DOUBLE |
\c Type::Float |
direct conversion |
\c DATE |
\c Type::Date |
direct conversion |
\c TIMESTAMP |
\c Type::Date (absolute) |
resolution to the microsecond |
\c TIMESTAMP \c WITH \c TIME \c ZONE |
\c Type::Date (absolute) |
includes time zone information and has a resolution to the microsecond |
\c TIMESTAMP \c WITH \c LOCAL \c TIME \c ZONE |
\c Type::Date (absolute) |
includes time zone information and has a resolution to the microsecond |
\c INTERVAL \c YEAR \c TO \c MONTH |
\c Type::Date (relative) |
direct conversion to a relative date |
\c INTERVAL \c DAY \c TO \c SECOND |
\c Type::Date (relative) |
direct conversion to a relative date |
\c SMALLINT, \c INTEGER |
\c Type::Int |
direct conversion |
\c NUMBER, \c NUMERIC, \c DECIMAL |
\c Type::String |
conversion to a string to avoid loss of precision |
\c CLOB |
\c Type::String |
the LOB handle is used to read the entire CLOB content into a string |
\c RAW, \c LONG RAW |
\c Type::Binary |
direct conversion |
\c BLOB |
\c Type::Binary |
the LOB handle is used to read the entire BLOB content into a binary object |
\c CURSOR (result set) |
\c Type::Hash |
the result set is returned as a hash of lists |
@subsection oracle_array_bind Oracle Array Binds
The Oracle driver supports the \c DBI_CAP_HAS_ARRAY_BIND capability, so it can find arrays of bind values to SQL for
highly efficient SQL communication with the server; data for an arbitrary number of rows can be sent to the server in
one command.
Array binding support differs depending on the data type; additionally it's possible to mix arrays of values and single
values when binding; single values will be repeated in each row bound.
Note that when arrays are bound; each array must have the same data type in each element or the element can contain
@ref nothing "NOTHING" or @ref null "NULL", both of which are bound as @ref null "NULL".
Function |
Description |
Qore::Oracle::bindOracleObject() |
Binds a Qore \c value as a Object type \c typename. Hash keys are object attributes |
Qore::Oracle::placeholderOracleObject() |
Allows fetching Object type \c typename. The returned hash is a plain Qore hash with keys set as the object's attributes |
Qore::Oracle::bindOracleCollection() |
Binds \c value as a Collection \c typename |
Qore::Oracle::placeholderOracleCollection() |
Allows fetching a Collection \c typename. The returned list is a plain Qore list of values with the collection's type |
Type names (strings) are case insensitive.
Key names in \c value hashes are case sensitive and should follow
Oracle uppercase naming convention.
Keys which are not found in the keys-attribute mappings are silently
ignored. If there is a missing key for any attribute, an exception is thrown.
@note Strings/integers are converted to date in collections and objects when required - collection of datetimes, object datetime attributes, etc. So eg. 1970-01-01 is the value of "wrong" strings.
Functions can be nested so there can be for example list (collection)
of objects and vice versa:
Sample named types defined in the DB:
@code
CREATE OR REPLACE TYPE test_object
AUTHID current_user AS OBJECT
(
attr_num number,
attr_varchar varchar2(20)
);
CREATE OR REPLACE TYPE test_collection IS TABLE OF test_object;
@endcode
Example of binding NTY:
@code
hash obj1 = ( "ATTR_NUM" : 1, "ATTR_VARCHAR" : "lorem ipsum" );
hash obj2 = ( "ATTR_NUM" : 2, "ATTR_VARCHAR" : "dolor sir amet" );
list l = ( bindOracleObject('test_object', obj1),
bindOracleObject('test_object', obj2) );
ds.exec("begin test_pkg.foo(%v); end;", bindOracleCollection('test_collection', l));
@endcode
Example of fetching NTY:
@code
*hash res = ds.exec("begin test_pkg.get_obj(:retval); end;",
placeholderOracleObject("TEST_OBJECT"));
printf("%N\n", res);
# will print out
hash: (
"ATTR_NUM" : 5,
"ATTR_VARCHAR" : "foobar!"
)
@endcode
@warning Oracle Named Types (objects and collections) are custom data types
stored directly in the Oracle system catalogue. They are real SQL
types - created with \c CREATE \c [ \c OR \c REPLACE \c ] \c TYPE
command. It's a common misundrestanding that PL/SQL types created
for example in package specification can be used as NTY too, however this is an
incorrect assumption. PL/SQL types cannot be used directly with the Oracle \c OCI
library, however you can use custom wrappers or any other workarounds, of course.
@section aq Oracle Advanced Queueing (AQ)
Oracle Advanced Queueing (AQ) is the Oracle database's queue management
feature. AQ provides a message queuing infrastructure as integral part
of the Oracle server engine. It provides an API for enqueing messages
to database queues. These messages can later be dequeued for asynchronous
processing. Oracle AQ also provides functionality to preserve, track,
document, correlate, and query messages in queues.
Features:
- synchronous message posting
- synchronouns message fetching
- asynchronous event-driven listening in the DB queue
Special initialization of the driver is mandatory to use AQ in Qore scripts:
@code
%requires oracle
@endcode
Qore Oracle module contains these classes to handle AQ: