13.4 AnyData Class
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. See Table 13-4 for supported data types.
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 13-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 13-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
before conversion.
Connection *conn; string str; ... if(!any.isNULL()) { if(any.getType()==OCCI_TYPECODE_VARCHAR2) { str = any.getAsString(); cout<<str; } } ...
Example 13-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 13-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
before 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 13-4 OCCI Data Types supported by AnyData Class
Data Type | 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 13-5 Summary of AnyData Methods
Method | Summary |
---|---|
|
|
Converts an |
|
Converts an |
|
Converts an |
|
Converts an |
|
Converts an |
|
Converts an |
|
Converts an |
|
Converts an |
|
Converts an |
|
Converts an |
|
Converts an |
|
Converts an |
|
Retrieves the DataType held by the |
|
Tests whether |
|
Converts a |
|
Converts a |
|
Converts a |
|
Converts a |
|
Converts a |
|
Converts an |
|
Converts an |
|
Converts a |
|
Converts a |
|
Converts a |
|
Converts a namespace |
|
Converts a |
|
Sets |
13.4.1 AnyData()
AnyData
constructor.
Syntax
AnyData( const Connection *conn);
Parameter | Description |
---|---|
conn |
The connection. |
13.4.7 getAsIntervalDS()
Converts an AnyData
object into IntervalDS
.
Syntax
IntervalDS getAsIntervalDS() const;
13.4.8 getAsIntervalYM()
Converts an AnyData
object into IntervalYM
.
Syntax
IntervalYS getAsIntervalYM() const;
13.4.12 getAsString()
Converts an AnyData
object into a namespace string
.
Syntax
string getAsString() const;
13.4.13 getAsTimestamp()
Converts an AnyData
object into Timestamp
.
Syntax
Timestamp getAsTimestamp() const;
13.4.14 getType()
Retrieves the data type held by the AnyData
object. Refer to Table 13-4 for valid values for TypeCode
.
Syntax
TypeCode getType();
13.4.15 isNull()
Tests whether the AnyData
object is NULL
. If the AnyData
object is NULL
, then TRUE
is returned; otherwise, FALSE
is returned.
Syntax
bool isNull() const;
13.4.16 setFromBDouble()
Converts a BDouble
into AnyData
.
Syntax
void setFromBDouble( const BDouble& bdouble);
Parameter | Description |
---|---|
bdouble |
The |
13.4.17 setFromBfile()
Converts a Bfile
into AnyData
.
Syntax
void setFromBfile( const Bfile& bfile);
Parameter | Description |
---|---|
bfile |
The |
13.4.18 setFromBFloat()
Converts a BFloat
into AnyData
.
Syntax
void setFromBFloat( const BFloat& bfloat);
Parameter | Description |
---|---|
bfloat |
The |
13.4.19 setFromBytes()
Converts a Bytes
into AnyData
.
Syntax
void setFromBytes( const Bytes& bytes);
Parameter | Description |
---|---|
bytes |
The |
13.4.20 setFromDate()
Converts a Date
into AnyData
.
Syntax
void setFromDate( const Date& date);
Parameter | Description |
---|---|
date |
The |
13.4.21 setFromIntervalDS()
Converts an IntervalDS
into AnyData
.
Syntax
void setFromIntervalDS( const IntervalDS& intervalds);
Parameter | Description |
---|---|
invtervalds |
The |
13.4.22 setFromIntervalYM()
Converts an IntervalYM
into AnyData
.
Syntax
void setFromIntervalYM( const IntervalYM& intervalym);
Parameter | Description |
---|---|
invalym |
The |
13.4.23 setFromNumber()
Converts a Number
into AnyData
.
Syntax
void setFromNumber( const Number& num);
Parameter | Description |
---|---|
num |
The |
13.4.24 setFromObject()
Converts a PObject
into AnyData
.
Syntax
void setFromObject( const PObject* objptr);
Parameter | Description |
---|---|
objptr |
The |
13.4.25 setFromRef()
Converts a PObject
into AnyData
.
Syntax
void setFromRef( const RefAny& ref const string &typeName, const string &schema);
Parameter | Description |
---|---|
ref |
The |
typeName |
The name of the type. |
schema |
The name of the schema where the type is defined. |
13.4.26 setFromString()
Converts a namespace string
into AnyData
.
Syntax
void setFromString( string& str);
Parameter | Description |
---|---|
str |
The namespace |
13.4.27 setFromTimestamp()
Converts a Timestamp
into AnyData
.
Syntax
void setFromTimestamp( const Timestamp& timestamp);
Parameter | Description |
---|---|
timestamp |
The |