Skip Headers
Oracle® C++ Call Interface Programmer's Guide,
11g Release 2 (11.2)

Part Number E10764-02
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Master Index
Master Index
Go to Feedback page
Contact Us

Go to previous page
Previous
Go to next page
Next
PDF · Mobi · ePub
LNCPP1028

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 setFromxxx() methods. An AnyData object can be converted into most SQL and user-defined types using getAsxxx() methods. SYS.ANYDATA type models AnyData both in SQL and PL/SQL. See Table 13-4, "OCCI Data Types supported by AnyData Class" 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.

LNCPP20531Example 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);
...

LNCPP20532Example 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;
   }
}
...

LNCPP20533Example 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);
...

LNCPP20534Example 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();
}
...

LNCPP20535Table 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

LNCPP20536Table 13-5 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 13-4.

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.


LNCPP20537

AnyData()

AnyData constructor.

LNCPP20538Syntax

AnyData(
   const Connection *conn); 
Parameter Description
conn
The connection.

LNCPP20539

getAsBDouble()

Converts an AnyData object into BDouble.

LNCPP20540Syntax

BDouble getAsBDouble() const;
LNCPP20541

getAsBfile()

Converts an AnyData object into Bfile.

LNCPP20542Syntax

Bfile getAsBfile() const;
LNCPP20543

getAsBFloat()

Converts an AnyData object into BFloat.

LNCPP20544Syntax

BFloat getAsBFloat() const;
LNCPP20545

getAsBytes()

Converts an AnyData object into Bytes.

LNCPP20546Syntax

Bytes getAsBytes() const;
LNCPP20547

getAsDate()

Converts an AnyData object into Date.

LNCPP20548Syntax

Date getAsDate() const;
LNCPP20549

getAsIntervalDS()

Converts an AnyData object into IntervalDS.

LNCPP20550Syntax

IntervalDS getAsIntervalDS() const;
LNCPP20551

getAsIntervalYM()

Converts an AnyData object into IntervalYM.

LNCPP20552Syntax

IntervalYS getAsIntervalYM() const;
LNCPP20553

getAsNumber()

Converts an AnyData object into Number.

LNCPP20554Syntax

Number getAsNumber() const;
LNCPP20555

getAsObject()

Converts an AnyData object into PObject.

LNCPP20556Syntax

PObject* getAsObject() const;
LNCPP20557

getAsRef()

Converts an AnyData object into RefAny.

LNCPP20558Syntax

RefAny getAsRef() const;
LNCPP20559

getAsString()

Converts an AnyData object into a namespace string.

LNCPP20560Syntax

string getAsString() const;
LNCPP20561

getAsTimestamp()

Converts an AnyData object into Timestamp.

LNCPP20562Syntax

Timestamp getAsTimestamp() const;
LNCPP20563

getType()

Retrieves the data type held by the AnyData object. Refer to Table 13-4 for valid values for TypeCode.

LNCPP20564Syntax

TypeCode getType();
LNCPP20565

isNull()

Tests whether the AnyData object is NULL. If the AnyData object is NULL, then TRUE is returned; otherwise, FALSE is returned.

LNCPP20566Syntax

bool isNull() const;
LNCPP20567

setFromBDouble()

Converts a BDouble into AnyData.

LNCPP20568Syntax

void setFromBDouble(
   const BDouble& bdouble);
Parameter Description
bdouble
The BDouble that is converted into AnyData.

LNCPP20569

setFromBfile()

Converts a Bfile into AnyData.

LNCPP20570Syntax

void setFromBfile(
   const Bfile& bfile);
Parameter Description
bfile
The Bfile that is converted into AnyData.

LNCPP20571

setFromBFloat()

Converts a BFloat into AnyData.

LNCPP20572Syntax

void setFromBFloat(
   const BFloat& bfloat);
Parameter Description
bfloat
The BFloat that is converted into AnyData.

LNCPP20573

setFromBytes()

Converts a Bytes into AnyData.

LNCPP20574Syntax

void setFromBytes(
   const Bytes& bytes);
Parameter Description
bytes
The Bytes that is converted into AnyData.

LNCPP20575

setFromDate()

Converts a Date into AnyData.

LNCPP20576Syntax

void setFromDate(
   const Date& date);
Parameter Description
date
The Date that is converted into AnyData.

LNCPP20577

setFromIntervalDS()

Converts an IntervalDS into AnyData.

LNCPP20578Syntax

void setFromIntervalDS(
   const IntervalDS& intervalds);
Parameter Description
invtervalds
The IntervalDS that is converted into AnyData.

LNCPP20579

setFromIntervalYM()

Converts an IntervalYM into AnyData.

LNCPP20580Syntax

void setFromIntervalYM(
   const IntervalYM& intervalym);
Parameter Description
invalym
The IntervalYM that is converted into AnyData.

LNCPP20581

setFromNumber()

Converts a Number into AnyData.

LNCPP20582Syntax

void setFromNumber(
   const Number& num);
Parameter Description
num
The Number that is converted into AnyData.

LNCPP20583

setFromObject()

Converts a PObject into AnyData.

LNCPP20584Syntax

void setFromObject(
   const PObject* objptr);
Parameter Description
objptr
The PObject that is converted into AnyData.

LNCPP20585

setFromRef()

Converts a PObject into AnyData.

LNCPP20586Syntax

void setFromRef(
   const RefAny& ref
   const string &typeName,
   const string &schema);
Parameter Description
ref
The RefAny that is converted into AnyData.
typeName
The name of the type.
schema
The name of the schema where the type is defined.

LNCPP20587

setFromString()

Converts a namespace string into AnyData.

LNCPP20588Syntax

void setFromString(
   string& str);
Parameter Description
str
The namespace string that is converted into AnyData.

LNCPP20589

setFromTimestamp()

Converts a Timestamp into AnyData.

LNCPP20590Syntax

void setFromTimestamp(
   const Timestamp& timestamp);
Parameter Description
timestamp
The Timestamp that is converted into AnyData.

LNCPP20591

setNull()

Sets AnyData object to NULL.

LNCPP20592Syntax

void setNull();
Reader Comment

   

Comments, corrections, and suggestions are forwarded to authors every week. By submitting, you confirm you agree to the terms and conditions. Use the OTN forums for product questions. For support or consulting, file a service request through My Oracle Support.

Hide Navigation

Quick Lookup

Database Library · Master Index · Master Glossary · Book List · Data Dictionary · SQL Keywords · Initialization Parameters · Advanced Search · Error Messages

Main Categories

This Page

This Document

New and changed documents:
RSS Feed HTML RSS Feed PDF