Oracle® C++ Call Interface Programmer's Guide 10g Release 1 (10.1) Part Number B10778-01 |
|
|
View PDF |
The AnyData
class models self-descriptive data by encapsulating the type information with the actual data. AnyData
is used primarily with OCCI Advanced Queuing feature, to represent and enqueue data and to receive messages from queues as AnyData
instances.
Most SQL and user-defined types can be converted into an AnyData
type using the setFrom
xxx
()
methods. An AnyData
object can be converted into most SQL and user-defined types using getAs
xxx
()
methods. SYS.ANYDATA
type models AnyData
both in SQL and PL/SQL.
The getType() call returns the TypeCode represented by an AnyData
object, while the isNull() call determines if AnyData
contains a NULL
value. The setNull() method sets the value of AnyData
to NULL
.
To use the OCCI AnyData
type, the environment has to be initiated in OBJECT
mode.
Example 10-1 Converting From an SQL Pre-Defined Type To AnyData Type
This example demonstrates how to convert types from string
to AnyData
.
Connection *conn; ... AnyData any(conn); string str("Hello World"); any.setFromString(str); ...
Example 10-2 Creating an SQL Pre-Defined Type From AnyData Type
This example demonstrates how to convert an AnyData
object back to a string
object. Note the use of getType() and isNull() methods to validate AnyData prior to conversion.
Connection *conn; string str; ... if(!any.isNULL()) { if(any.getType()==OCCI_TYPECODE_VARCHAR2) { str = any.getAsString(); cout<<str; } } ...
Example 10-3 Converting From a User-Defined Type To AnyData Type
This example demonstrates how to convert from a user-defined type to AnyData
type.
Connection *conn; ... // Assume an OBJECT of type Person with the following defined fields // CREATE TYPE person as OBJECT ( // FRIST_NAME VARCHAR2(20), // LAST_NAME VARCHAR2(25), // EMAIL VARCHAR2(25), // SALARY NUMBER(8,2) // ); // Assume relevant classes have been generated by OTT. ... Person *pers new Person( "Steve", "Addams", "steve.addams@anycompany.com", 50000.00); AnyData anyObj(conn); anyObj.setFromObject(pers); ...
Example 10-4 Converting From a User-Defined Type To AnyData Type
This example demonstrates how to convert an AnyData
object back to a user-defined type. Note the use of getType() and isNull() methods to validate AnyData prior to conversion.
Connection *conn; // Assume an OBJECT of type Person with the following defined fields // CREATE TYPE person as OBJECT ( // FRIST_NAME VARCHAR2(20), // LAST_NAME VARCHAR2(25), // EMAIL VARCHAR2(25), // SALARY NUMBER(8,2) // ); // Assume relevant classes have been generated by OTT. Person *pers = new Person(); ... If(!anyObj.isNull()) { if(anyObj.getType()==OCCI_TYPECODE_OBJECT) pers = anyObj.getAsObject(); } ...
Table 10-3 OCCI Datatypes supported by AnyData Class
Datatype | TypeCode |
---|---|
BDouble |
OCCI_TYPECODE_BDOUBLE |
BFile |
OCCI_TYPECODE_BFILE |
BFloat |
OCCI_TYPECODE_BFLOAT |
Bytes |
OCCI_TYPECODE_RAW |
Date |
OCCI_TYPECODE_DATE |
IntervalDS |
OCCI_TYPECODE_INTERVAL_DS |
IntervalYM |
OCCI_TYPECODE_INTERVAL_YM |
Number |
OCCI_TYPECODE_NUMBERB |
PObject |
OCCI_TYPECODE_OBJECT |
Ref |
OCCI_TYPECODE_REF |
string |
OCCI_TYPECODE_VARCHAR2 |
TimeStamp |
OCCI_TYPECODE_TIMESTAMP |
Table 10-4 Summary of AnyData Methods
Method | Summary |
---|---|
AnyData() |
AnyData class constructor. |
getAsBDouble() |
Converts an AnyData object into BDouble . |
getAsBfile() |
Converts an AnyData object into Bfile . |
getAsBFloat() |
Converts an AnyData object into BFloat . |
getAsBytes() |
Converts an AnyData object into Bytes . |
getAsDate() |
Converts an AnyData object into Date . |
getAsIntervalDS() |
Converts an AnyData object into IntervalDS . |
getAsIntervalYM() |
Converts an AnyData object into IntervalYM . |
getAsNumber() |
Converts an AnyData object into Number . |
getAsObject() |
Converts an AnyData object into PObject . |
getAsRef() |
Converts an AnyData object into RefAny . |
getAsString() |
Converts an AnyData object into a namespace string . |
getAsTimestamp() |
Converts an AnyData object into Timestamp. |
getType() |
Retrieves the DataType held by the AnyData object. See Table 10-3. |
isNull() |
Tests whether AnyData object is NULL . |
setFromBDouble() |
Converts a BDouble into Anydata . |
setFromBfile() |
Converts a Bfile into Anydata . |
setFromBFloat() |
Converts a BFloat into Anydata . |
setFromBytes() |
Converts a Bytes into Anydata . |
setFromDate() |
Converts a Date into Anydata . |
setFromIntervalDS() |
Converts an IntervalDS into Anydata . |
setFromIntervalYM() |
Converts an IntervalYM into Anydata . |
setFromNumber() |
Converts a Number into Anydata . |
setFromObject() |
Converts a PObject into Anydata . |
setFromRef() |
Converts a RefAny into Anydata . |
setFromString() |
Converts a namespace string into Anydata . |
setFromTimestamp() |
Converts a Timestamp into Anydata . |
setNull() |
Sets AnyData object to NULL . |
AnyData
constructor.
AnyData( const Connection *sessp);
Parameter | Description |
---|---|
sessp |
The connection. |
Converts an AnyData
object into BDouble
.
BDouble getAs2BDouble() const;
Converts an AnyData
object into Bfile
.
Bfile getAsBfile() const;
Converts an AnyData
object into BFloat
.
BFloat getAsBFloat() const;
Converts an AnyData
object into Bytes.
Bytes getAsBytes() const;
Converts an AnyData
object into Date
.
Date getAsDate() const;
Converts an AnyData
object into IntervalDS
.
IntervalDS getAsIntervalDS() const;
Converts an AnyData
object into IntervalYM
.
IntervalYS getAsIntervalYM() const;
Converts an AnyData
object into Number
.
Number getAsNumber() const;
Converts an AnyData
object into PObject
.
PObject* getAsObject() const;
Converts an AnyData
object into RefAny
.
RefAny getAsRef() const;
Converts an AnyData
object into a namespace string
.
string getAsString() const;
Converts an AnyData
object into Timestamp
.
Timestamp getAsTimestamp() const;
Retrieves the data type held by the AnyData
object. Refer to Table 10-3 for valid values for TypeCode
.
TypeCode getType();
Tests whether the AnyData
object is NULL
. If the AnyData
object is NULL
, then TRUE
is returned; otherwise, FALSE
is returned.
bool isNull() const;
Converts a BDouble
into AnyData
.
void setFromBDouble( const BDouble& bd);
Parameter | Description |
---|---|
bd |
The BDouble that will be converted into AnyData . |
Converts a Bfile
into AnyData
.
void setFromBfile( const Bfile& bfile);
Parameter | Description |
---|---|
bfile |
The Bfile that will be converted into AnyData . |
Converts a BFloat
into AnyData
.
void setFromBFloat( const BFloat& bf);
Parameter | Description |
---|---|
bf |
The BFloat that will be converted into AnyData . |
Converts a Bytes
into AnyData
.
void setFromBytes( const Bytes& bytes);
Parameter | Description |
---|---|
bytes |
The Bytes that will be converted into AnyData . |
Converts a Date
into AnyData
.
void setFromDate( const Date& date);
Parameter | Description |
---|---|
date |
The Date that will be converted into AnyData . |
Converts an IntervalDS
into AnyData
.
void setFromIntervalDS( const IntervalDS& invDS);
Parameter | Description |
---|---|
invDS |
The IntervalDS that will be converted into AnyData . |
Converts an IntervalYM
into AnyData
.
void setFromIntervalYM( const IntervalYM& invYM);
Parameter | Description |
---|---|
invYM |
The IntervalYM that will be converted into AnyData . |
Converts a Number
into AnyData
.
void setFromNumber( const Number& num);
Parameter | Description |
---|---|
num |
The Number that will be converted into AnyData . |
Converts a PObject
into AnyData
.
void setFromObject( const PObject* objptr);
Parameter | Description |
---|---|
objptr |
The PObject that will be converted into AnyData . |
Converts a PObject
into AnyData
.
void setFromRef( const RefAny& ref);
Parameter | Description |
---|---|
ref |
The RefAny that will be converted into AnyData . |
Converts a namespace string
into AnyData
.
void setFromString( string& str);
Parameter | Description |
---|---|
str |
The namespace string that will be converted into AnyData . |
Converts a Timestamp
into AnyData
.
void setFromTimestamp( const Timestamp& timestamp);
Parameter | Description |
---|---|
timestamp |
The Timestamp that will be converted into AnyData . |
Sets AnyData object
to NULL
.
void setNull();