Oracle Call Interface Programmer's Guide
Release 8.1.5

A67846-01

Library

Product

Contents

Index

Prev Next

16
OCI Navigational and Type Functions

This chapter describes the OCI navigational functions which are used to navigate through objects retrieved from an Oracle database server. It also contains the descriptions of the functions which are used to obtain type descriptor objects (TDOs). The chapter contains the following sections:

Introduction

In an object navigational paradigm, data is represented as a graph of objects connected by references. Objects in the graph are reached by following the references. The OCI provides a navigational interface to objects in the Oracle server. Those calls are described in this chapter.

The OCI object environment is initialized when the application calls OCIInitialize() in OCI_OBJECT mode.

See Also: For more information about using the calls in this chapter, refer to Chapter 10, "OCI Object-Relational Programming", and Chapter 13, "Object Cache and Object Navigation".

Object Types and Lifetimes

An object instance is an occurrence of a type defined in an Oracle database. This section describes how an object instance can be represented in OCI. See Figure 16-1. In OCI, an object instance can be classified based on the type, the lifetime and referenceability:

A value can be standalone or embedded. A standalone value is usually obtained by issuing a select statement. OCI also allows the client program to select a row of object table into a value by issuing a SQL statement. A referenceable object in the database can be represented as a value which cannot be identified by a reference. A standalone value can also be an out-of-line attribute in an object, such as VARCHAR or raw, or an out-of-line element in a collection, such as VARCHAR, raw, or object.

An embedded value is physically included in a containing instance. An embedded value can be an in-line attribute in an object. such as number or nested object, or an in-line element in a collection.

All values are considered to be transient by OCI, which means that OCI does not support automatic flushing a value to the database, and the client has to explicitly execute a SQL statement to store a value into the database. For embedded values, they are flushed when their containing instance are flushed.

Figure 16-1 shows how instances can be classified according to their type and lifetime:

Figure 16-1 Classification of Instances by Type and Lifetime


The distinction between various instances is further illustrated by the following table:

  Persistent Object   Transient Object   Value  

Type  

object type  

object type  

object type, built-in, collection  

Maximum Lifetime  

until object is deleted  

session  

session  

Referenceable  

yes  

yes  

no  

Embeddable  

no  

no  

yes  

Terminology

In the remainder of this chapter, the following terms will be used:

For a further discussion of the terms used to refer to different types of objects, please see "Persistent Objects, Transient Objects, and Values".

The Function Syntax

The entries for each function contain the following information:

Purpose

A brief description of what the function does.

Syntax

A code snippet showing the syntax for calling the function, including the ordering and types of the parameters.

Comments

Detailed information about the function if available. This may include restrictions on the use of the function, or other information that might be useful when using the function in an application.

Parameters

A description of each of the function's parameters. This includes the parameter's mode. The mode of a parameter has three possible values, as described below:

Mode   Description  

IN  

A parameter that passes data to Oracle  

OUT  

A parameter that receives data from Oracle on this or a subsequent call  

IN/OUT  

A parameter that passes data on the call and receives data on the return from this or a subsequent call.  

Returns

A description of what value is returned by the function if the function returns something other than the standard return codes listed above.

Related Functions

A list of related calls which may provide additional useful information.

Navigational Function Return Values

The OCI navigational functions typically return one of the following values:

Return Value   Meaning  

OCI_SUCCESS  

The operation succeeded  

OCI_ERROR  

The operation failed. The specific error can be retrieved by calling OCIErrorGet() on the error handle passed to the function.  

OCI_INVALID_HANDLE  

The environment or error handle passed to the function is NULL.  

Function-specific return information follows the description of each function in this chapter. Information about specific error codes returned by each function is presented in the following section.

See Also: For more information about return codes and error handling, see the section "Error Handling".

Server Roundtrips for Cache and Object Functions

For a table showing the number of server roundtrips required for individual OCI cache and object functions, refer to Appendix C, "OCI Function Server Roundtrips".

Navigational Function Error Codes

Table 16-1 lists the external Oracle error codes which can be returned by each of the OCI navigational functions. The list following the table identifies what each error represents.

Table 16-1 OCI Navigational Functions Error Codes
Function  Possible ORA Errors 

OCICacheFlush()  

24350, 21560, 21705  

OCICacheFree()  

24350, 21560, 21705  

OCICacheRefresh()  

24350, 21560, 21705  

OCICacheUnmark()  

24350, 21560, 21705  

OCICacheUnpin()  

24350, 21560, 21705  

OCIObjectArrayPin()  

24350, 21560  

OCIObjectCopy()  

24350, 21560, 21705, 21710  

OCIObjectExists()  

24350, 21560, 21710  

OCIObjectFlush()  

24350, 21560, 21701, 21703, 21708, 21710  

OCIObjectFree()  

24350, 21560, 21603, 21710  

OCIObjectGetAttr()  

21560, 21600, 22305  

OCIObjectGetInd()  

24350, 21560, 21710  

OCIObjectGetTypeRef()  

24350, 21560, 21710  

OCIObjectIsDirty()  

24350, 21560, 21710  

OCIObjectIsLocked()  

24350, 21560, 21710  

OCIObjectLock()  

24350, 21560, 21701, 21708, 21710  

OCIObjectLockNoWait()  

24350, 21560, 21701, 21708, 21710  

OCIObjectMarkDelete()  

24350, 21560, 21700, 21701, 21702, 21710  

OCIObjectMarkDeleteByRef()  

24350, 21560  

OCIObjectMarkUpdate()  

24350, 21560, 21700, 21701, 21710  

OCIObjectNew()  

24350, 21560, 21705, 21710  

OCIObjectPin()  

24350, 21560, 21700, 21702  

OCIObjectPinCountReset()  

24350, 21560, 21710  

OCIObjectPinTable()  

24350, 21560, 21705  

OCIObjectRefresh()  

24350, 21560, 21709, 21710  

OCIObjectSetAttr()  

21560, 21600, 22305, 22279, 21601  

OCIObjectUnmark()  

24350, 21560, 21710  

OCIObjectUnmarkByRef()  

24350, 21560  

OCIObjectUnpin()  

24350, 21560, 21710  

OCIOjectGetObjectRef()  

24350, 21560, 21710  

The ORA errors in Table 16-1 have the following meanings.

OCI Flush or Refresh Functions

This section describes the OCI flush or refresh functions.

Table 16-2 OCI Flush or Refresh Functions Quick Reference
Function/Page  Purpose 

OCICacheFlush()  

Flush modified persistent objects in cache to server  

OCICacheRefresh()  

Refresh pinned persistent objects  

OCIObjectFlush()  

Flush a modified persistent object to the server  

OCIObjectRefresh()  

Refresh a persistent object  


OCICacheFlush()

Purpose

Flushes modified persistent objects to the server

Syntax

sword OCICacheFlush ( OCIEnv              *env, 
                      OCIError            *err, 
                      CONST OCISvcCtx     *svc, 
                      dvoid               *context,
                      OCIRef              *(*get)
                                          ( dvoid   *context,
                                            ub1     *last ), 
                      OCIRef              **ref );

Parameters

env (IN/OUT)

The OCI environment handle initialized in object mode. See the description of OCIEnvCreate() and OCIInitialize() in Chapter 15 for more information.

err (IN/OUT)

The OCI error handle. If there is an error, it is recorded in err and this function returns OCI_ERROR. Obtain diagnostic information by calling OCIErrorGet().

svc (IN)

OCI service context.

context (IN) [optional]

Specifies an user context that is an argument to the client callback function get. This parameter is set to NULL if there is no user context.

get (IN) [optional]

A client-defined function which acts an iterator to retrieve a batch of dirty objects that need to be flushed. If the function is not NULL, this function will be called to get a reference of a dirty object. This is repeated until a null reference is returned by the client function or the parameter last is set to TRUE. The parameter context is passed to get() for each invocation of the client function. This parameter should be NULL if user callback is not given. If the object that is returned by the client function is not a dirtied persistent object, the object is ignored.

All the objects that are returned from the client function must be newed or pinned using the same service context, otherwise an error is signalled. Note that the cache flushes the returned objects in the order in which they were marked dirty.

If this parameter is passed as NULL (e.g., no client-defined function is provided), then all dirty persistent objects for the given service context are flushed in the order in which they were dirtied.

ref (OUT) [optional]

If there is an error in flushing the objects (*ref) will point to the object that is causing the error. If ref is NULL, then the object will not be returned. If *ref is NULL, then a reference will be allocated and set to point to the object. If *ref is not NULL, then the reference of the object is copied into the given space. If the error is not caused by any of the dirtied object, the given REF is initialized to be a NULL reference (OCIRefIsNull(*ref) is TRUE).

The REF is allocated for session duration (OCI_DURATION_SESSION). The application can free the allocated REF using the OCIObjectFree() function.

Comments

This function flushes the modified persistent objects from the object cache to the server. The objects are flushed in the order that they are newed or marked updated or deleted. See OCIObjectFlush() for more information about flushing.

This function incurs at most one network round-trip.

Related Functions

OCIObjectFlush()


OCICacheRefresh()

Purpose

Refreshes all pinned persistent objects in the cache.

Syntax

sword OCICacheRefresh ( OCIEnv            *env, 
                       OCIError           *err, 
                       CONST OCISvcCtx    *svc,
                       OCIRefreshOpt      option, 
                       dvoid              *context,
                       OCIRef             *(*get)(dvoid *context), 
                       OCIRef             **ref );

Parameters

env (IN/OUT)

The OCI environment handle initialized in object mode. See the description of OCIEnvCreate() and OCIInitialize() in Chapter 15 for more information.

err (IN/OUT)

The OCI error handle. If there is an error, it is recorded in err and this function returns OCI_ERROR. Obtain diagnostic information by calling OCIErrorGet().

svc (IN)

OCI service context.

option (IN) [optional]

If OCI_REFRESH_LOADED is specified, all objects that are loaded within the transaction are refreshed. If the option is OCI_REFRESH_LOADED and the parameter get is not NULL, this function will ignore the parameter.

context (IN) [optional]

Specifies an user context that is an argument to the client callback function get. This parameter is set to NULL if there is no user context.

get (IN) [optional]

A client-defined function which acts an iterator to retrieve a batch of objects that need to be refreshed. If the function is not NULL, this function will be called to get a reference of an object. If the reference is not NULL, then the object will be refreshed. These steps are repeated until a null reference is returned by this function. The parameter context is passed to get() for each invocation of the client function. This parameter should be NULL if user callback is not given.

ref (OUT) [optional]

If there is an error in refreshing the objects, (*ref) will point to the object that is causing the error. If ref is NULL, then the object will not be returned. If *ref is NULL, then a reference will be allocated and set to point to the object. If *ref is not NULL, then the reference of the object is copied into the given space. If the error is not caused by any of the object, the given ref is initialized to be a NULL reference (OCIRefIsNull(*ref) is TRUE).

Comments

This function refreshes all pinned persistent objects and all unpinned persistent objects are freed from the object cache.

For more information about refreshing, see the description of OCIObjectRefresh(), and the section "Refreshing an Object Copy".

Warning: When objects are refreshed, the secondary-level memory of those objects could potentially move to a different place in memory. As a result, any pointers to attributes which were saved prior to this call may be invalidated. Examples of attributes using secondary-level memory include OCIString *, OCIColl *, and OCIRaw *.

Related Functions

OCIObjectRefresh()


OCIObjectFlush()

Purpose

Flushes a modified persistent object to the server.

Syntax

sword OCIObjectFlush ( OCIEnv        *env,
                       OCIError      *err,
                       dvoid         *object );

Parameters

env (IN/OUT)

The OCI environment handle initialized in object mode. See the description of OCIEnvCreate() and OCIInitialize() in Chapter 15 for more information.

err (IN/OUT)

The OCI error handle. If there is an error, it is recorded in err and this function returns OCI_ERROR. Obtain diagnostic information by calling OCIErrorGet().

object (IN)

A pointer to the persistent object. The object must be pinned before this call.

Comments

This function flushes a modified persistent object to the server. An exclusive lock is obtained implicitly for the object when it is flushed. When the object is written to the server, triggers may be fired. This function returns an error for transient objects and values, and for unmodified persistent objects.

Objects can be modified by triggers at the server. To keep objects in the cache consistent with the database, an application can free or refresh objects in the cache.

If the object to flush contains an internal LOB attribute and the LOB attribute was modified due to an OCIObjectCopy(), OCILobAssign(), or OCILobLocatorAssign() or by assigning another LOB locator to it, then the flush makes a copy of the LOB value that existed in the source LOB at the time of the assignment or copy of the internal LOB locator or object. For more information on LOB functions, see "LOB Functions".

Related Functions

OCIObjectPin(), OCICacheFlush()


OCIObjectRefresh()

Purpose

Refreshes a persistent object from the most current database snapshot.

Syntax

sword OCIObjectRefresh ( OCIEnv        *env, 
                         OCIError      *err, 
                         dvoid         *object );

Parameters

env (IN/OUT)

The OCI environment handle initialized in object mode. See the description of OCIEnvCreate() and OCIInitialize() in Chapter 15 for more information.

err (IN/OUT)

The OCI error handle. If there is an error, it is recorded in err and this function returns OCI_ERROR. Obtain diagnostic information by calling OCIErrorGet().

object (IN)

A pointer to the persistent object, which must already be pinned.

Comments

This function refreshes an object with data retrieved from the latest snapshot in the server. An object should be refreshed when the objects in the object cache are inconsistent with the objects at the server.

Note: When an object is flushed to the server, triggers can be fired to modify more objects in the server. The same objects (modified by the triggers) in the object cache become out-of-date, and must be refreshed before they can be locked or flushed.

This occurs when the user issues a SQL statement or PL/SQL procedure to modify any object in the server.

Warning: Modifications made to objects (dirty objects) since the last flush are lost if object are refreshed by this function.

The various meta-attribute flags and durations of an object are modified after being refreshed:

Object Attribute   Status After Refresh  

existent  

set to appropriate value  

pinned  

unchanged  

allocation duration  

unchanged  

pin duration  

unchanged  

The object that is refreshed will be replaced-in-place. When an object is replaced-in-place, the top-level memory of the object will be reused so that new data can be loaded into the same memory address. The top level memory of the null structure is also reused. Unlike the top-level memory chunk, the secondary memory chunks will be freed and reallocated.

You should be careful when writing functionality that holds on to a pointer to the secondary memory chunk, such as assigning the address of a secondary memory to a local variable, because this pointer can become invalid after the object is refreshed.

This function does nothing for transient objects or values.

Related Functions

OCICacheRefresh()

OCI Mark or Unmark Object and Cache Functions

This section describe the OCI mark or unmark Object and Cache functions.

Table 16-3 OCI Navigational Functions Quick Reference
Function/Page  Purpose 

OCICacheUnmark()  

Unmarks objects in the cache  

OCIObjectMarkDelete()  

Mark an object deleted / delete a value instance  

OCIObjectMarkDeleteByRef()  

Mark an object deleted given a ref  

OCIObjectMarkUpdate()  

Mark an object as updated/dirty  

OCIObjectUnmark()  

Unmarks an object  

OCIObjectUnmarkByRef()  

Unmarks an object, given a ref to it  


OCICacheUnmark()

Purpose

Unmarks all dirty objects in the object cache.

Syntax

sword OCICacheUnmark ( OCIEnv            *env, 
                       OCIError          *err,
                       CONST OCISvcCtx   *svc );

Parameters

env (IN/OUT)

The OCI environment handle initialized in object mode. See the description of OCIEnvCreate() and OCIInitialize() in Chapter 15 for more information.

err (IN/OUT)

The OCI error handle. If there is an error, it is recorded in err and this function returns OCI_ERROR. Obtain diagnostic information by calling OCIErrorGet().

svc (IN)

OCI service context.

Comments

If a connection is specified, this function unmarks all dirty objects in that connection. Otherwise, all dirty objects in the cache are unmarked. See OCIObjectUnmark() for more information about unmarking an object.

Related Functions

OCIObjectUnmark()


OCIObjectMarkDelete()

Purpose

Marks a standalone instance as deleted, given a pointer to the instance.

Syntax

sword OCIObjectMarkDelete ( OCIEnv        *env, 
                            OCIError      *err, 
                            dvoid         *instance );

Parameters

env (IN/OUT)

The OCI environment handle initialized in object mode. See the description of OCIEnvCreate() and OCIInitialize() in Chapter 15 for more information.

err (IN/OUT)

The OCI error handle. If there is an error, it is recorded in err and this function returns OCI_ERROR. Obtain diagnostic information by calling OCIErrorGet().

instance (IN)

Pointer to the instance. It must be standalone, and if it is an object it must be pinned.

Comments

This function accepts a pointer to a standalone instance and marks the object as deleted. The object is freed according to the following rules:

For Persistent Objects

The object is marked deleted. The memory of the object is not freed. The object is deleted in the server when the object is flushed.

For Transient Objects

The object is marked deleted. The memory of the object is not freed.

For Values

This function frees a value immediately.

Related Functions

OCIObjectMarkDeleteByRef(), OCIObjectGetProperty()


OCIObjectMarkDeleteByRef()

Purpose

Marks an object as deleted, given a reference to the object.

Syntax

sword OCIObjectMarkDeleteByRef ( OCIEnv         *env, 
                                 OCIError       *err, 
                                 OCIRef         *object_ref );

Parameters

env (IN/OUT)

The OCI environment handle initialized in object mode. See the description of OCIEnvCreate() and OCIInitialize() in Chapter 15 for more information.

err (IN/OUT)

The OCI error handle. If there is an error, it is recorded in err and this function returns OCI_ERROR. Obtain diagnostic information by calling OCIErrorGet().

object_ref (IN)

Reference to the object to be deleted.

Comments

This function accepts a reference to an object, and marks the object designated by object_ref as deleted. The object is marked and freed as follows:

For Persistent Objects

If the object is not loaded, then a temporary object is created and is marked deleted. Otherwise, the object is marked deleted.

The object is deleted in the server when the object is flushed.

For Transient Objects

The object is marked deleted. The object is not freed until it is unpinned.

Related Functions

OCIObjectMarkDelete(), OCIObjectGetProperty()


OCIObjectMarkUpdate()

Purpose

Marks a persistent object as updated, or dirty.

Syntax

sword OCIObjectMarkUpdate ( OCIEnv        *env,
                            OCIError      *err, 
                            dvoid         *object );

Parameters

env (IN/OUT)

The OCI environment handle initialized in object mode. See the description of OCIEnvCreate() and OCIInitialize() in Chapter 15 for more information.

err (IN/OUT)

The OCI error handle. If there is an error, it is recorded in err and this function returns OCI_ERROR. Obtain diagnostic information by calling OCIErrorGet().

object (IN)

A pointer to the persistent object, which must already be pinned.

Comments

This function marks a persistent object as updated, or dirty. The following special rules apply to different types of objects. The dirty status of an object may be checked by calling OCIObjectIsLocked().

For Persistent Objects

This function marks the specified persistent object as updated.

The persistent objects will be written to the server when the object cache is flushed. The object is not locked or flushed by this function. It is an error to update a deleted object.

After an object is marked updated and flushed, this function must be called again to mark the object as updated if it has been dirtied after it is being flushed.

For Transient Objects

This function marks the specified transient object as updated. The transient objects will NOT be written to the server. It is an error to update a deleted object.

For Values

This function is an no-op for values.

For more information about the use of this function, see "Marking Objects and Flushing Changes".

Related Functions

OCIObjectPin(), OCIObjectGetProperty()


OCIObjectUnmark()

Purpose

Unmarks an object as dirty.

Syntax

sword OCIObjectUnmark ( OCIEnv       *env,
                        OCIError     *err,
                        dvoid        *object );

Parameters

env (IN/OUT)

The OCI environment handle initialized in object mode. See the description of OCIEnvCreate() and OCIInitialize() in Chapter 15 for more information.

err (IN/OUT)

The OCI error handle. If there is an error, it is recorded in err and this function returns OCI_ERROR. Obtain diagnostic information by calling OCIErrorGet().

object (IN)

Pointer to the persistent object. It must be pinned.

Comments

For Persistent Objects and Transient Objects

This function unmarks the specified persistent object as dirty. Changes that are made to the object will not be written to the server. If the object is marked locked, it remains marked locked. The changes that have already made to the object will not be undone implicitly.

For Values

This function is an no-op for values. This means that the function will have no effect if called on a value.

Related Functions

OCIObjectUnmarkByRef()


OCIObjectUnmarkByRef()

Purpose

Unmarks an object as dirty, given a REF to the object.

Syntax

sword OCIObjectUnmarkByRef ( OCIEnv      *env, 
                             OCIError    *err,
                             OCIRef      *ref );

Parameters

env (IN/OUT)

The OCI environment handle initialized in object mode. See the description of OCIEnvCreate() and OCIInitialize() in Chapter 15 for more information.

err (IN/OUT)

The OCI error handle. If there is an error, it is recorded in err and this function returns OCI_ERROR. Obtain diagnostic information by calling OCIErrorGet().

ref (IN)

Reference of the object. It must be pinned.

Comments

This function unmarks an object as dirty. This function is identical to OCIObjectUnmark(), except that it takes a REF to the object as an argument.

For Persistent Objects and Transient Objects

This function unmarks the specified persistent object as dirty. Changes that are made to the object will not be written to the server. If the object is marked locked, it remains marked locked. The changes that have already made to the object will not be undone implicitly.

For Values

This function is a no-op for values.

Related Functions

OCIObjectUnmark()

OCI Get Object Status Functions

This section describes the OCI get object status functions.

Table 16-4 OCI Navigational Functions Quick Reference
Function/Page  Purpose 

OCIObjectExists()  

Get the existent status of an instance  

OCIObjectGetProperty()  

Get the status of a particular object property  

OCIObjectIsLocked()  

Get the dirtied status of an instance  

OCIObjectIsLocked()  

Get the locked status of an instance  


OCIObjectExists()

Purpose

Returns the existence meta-attribute of a standalone instance.

Syntax

sword OCIObjectExists ( OCIEnv         *env,
                        OCIError       *err,
                        dvoid          *ins,
                        boolean        *exist ); 

Parameters

env (IN/OUT)

The OCI environment handle initialized in object mode. See the description of OCIEnvCreate() and OCIInitialize() in Chapter 15 for more information.

err (IN/OUT)

The OCI error handle. If there is an error, it is recorded in err and this function returns OCI_ERROR. Obtain diagnostic information by calling OCIErrorGet().

ins (IN)

Pointer to an instance. If it is an object, it must be pinned.

exist (OUT)

Return value for the existence status.

Comments

This function returns the existence of an instance. If the instance is a value, this function always returns TRUE. The instance must be a standalone persistent or transient object.

For more information about object meta-attributes, see "Object Meta-Attributes".

Related Functions

OCIObjectPin()


OCIObjectGetProperty()

Purpose

Retrieve a given property of an object.

Syntax

sword OCIObjectGetProperty ( OCIEnv              *envh, 
                             OCIError            *errh, 
                             CONST dvoid         *obj, 
                             OCIObjectPropId     propertyId,
                             dvoid               *property, 
                             ub4                 *size );

Parameters

env (IN/OUT)

The OCI environment handle initialized in object mode. See the description of OCIEnvCreate() and OCIInitialize() in Chapter 15 for more information.

err (IN/OUT)

The OCI error handle. If there is an error, it is recorded in err and this function returns OCI_ERROR. Obtain diagnostic information by calling OCIErrorGet().

obj (IN)

The object whose property is returned.

propertyId (IN)

The identifier which identifies the desired property.

property (OUT)

The buffer into which the desired property is copied.

size (IN/OUT)

On input, this parameter specifies the size of the property buffer passed by caller.

On output it contains the size in bytes of the property returned. This parameter is required for string-type properties only, such as OCI_OBJECTPROP_SCHEMA, OCI_OBJECTPROP_TABLE). For non-string properties this parameter is ignored since the size is fixed.

Comments

This function returns the specified property of the object. The desired property is identified by propertyId. The property value is copied into property and for string typed properties the string size is returned via size.

Objects are classified as persistent, transient and value depending upon the lifetime and referenceability of the object. Some of the properties are applicable only to persistent objects and some others only apply to persistent and transient objects. An error is returned if the user tries to get a property which in not applicable to the given object. To avoid such an error, the user should first check whether the object is persistent or transient or value (OCI_OBJECTPROP_LIFETIME property) and then appropriately query for other properties.

The different property ids and the corresponding type of property argument are given below.

OCI_OBJECTPROP_LIFETIME

This identifies whether the given object is a persistent object or a transient object or a value instance. The property argument must be a pointer to a variable of type OCIObjectLifetime. Possible values include:

OCI_OBJECTPROP_SCHEMA

This returns the schema name of the table in which the object exists. An error is returned if the given object points to a transient instance or a value. If the input buffer is not big enough to hold the schema name an error is returned, the error message will communicate the required size. Upon success, the size of the returned schema name in bytes is returned via size. The property argument must be an array of type text and size should be set to size of array in bytes by the caller.

OCI_OBJECTPROP_TABLE

This returns the table name in which the object exists. An error is returned if the given object points to a transient instance or a value. If the input buffer is not big enough to hold the table name an error is returned, the error message will communicate the required size. Upon success, the size of the returned table name in bytes is returned via size. The property argument must be an array of type text and size should be set to size of array in bytes by the caller.

OCI_OBJECTPROP_PIN_DURATION

This returns the pin duration of the object. An error is returned if the given object points to a value instance. The property argument must be a pointer to a variable of type OCIDuration. Valid values include

For more information about durations, see "Object Duration".

OCI_OBJECTPROP_ALLOC_DURATION

This returns the allocation duration of the object. The property argument must be a pointer to a variable of type OCIDuration. Valid values include:

For more information about durations, see "Object Duration".

OCI_OBJECTPROP_LOCK

This returns the lock status of the object. The possible lock statuses are enumerated by OCILockOpt. An error is returned if the given object points to a transient or value instance. The property argument must be a pointer to a variable of type OCILockOpt. Note, the lock status of an object can also be retrieved by calling OCIObjectIsLocked(). Valid values include:

OCI_OBJECTPROP_MARKSTATUS

This returns the dirty status and indicates whether the object is a new object, updated object or deleted object. An error is returned if the given object points to a transient or value instance. The property argument must be of type OCIObjectMarkStatus. Valid values include:

The following macros are available to test the object mark status:

OCI_OBJECTPROP_VIEW

This identifies whether the specified object is a view object or not. If the property value returned is TRUE, it indicates the object is a view otherwise it is not. An error is returned if the given object points to a transient or value instance. The property argument must be of type boolean.

Related Functions

OCIObjectLock(), OCIObjectMarkDelete(), OCIObjectMarkUpdate(), OCIObjectPin(), OCIObjectPin()


OCIObjectIsDirty()

Purpose

Checks to see if an object is marked as dirty.

Syntax

sword OCIObjectIsDirty ( OCIEnv       *env,
                         OCIError     *err, 
                         dvoid        *ins,
                         boolean      *dirty );

Parameters

env (IN/OUT)

The OCI environment handle initialized in object mode. See the description of OCIEnvCreate() and OCIInitialize() in Chapter 15 for more information.

err (IN/OUT)

The OCI error handle. If there is an error, it is recorded in err and this function returns OCI_ERROR. Obtain diagnostic information by calling OCIErrorGet().

ins (IN)

Pointer to an instance.

dirty (OUT)

Return value for the dirty status.

Comments

The instance passed to this function must be standalone. If the instance is an object, the instance must be pinned.

This function returns the dirty status of an instance. If the instance is a value, this function always returns FALSE for the dirty status.

Related Functions

OCIObjectMarkUpdate(), OCIObjectGetProperty()


OCIObjectIsLocked()

Purpose

Get lock status of an object.

Syntax

sword OCIObjectIsLocked ( OCIEnv       *env, 
                          OCIError     *err, 
                          dvoid        *ins,
                          boolean      *lock );

Parameters

env (IN/OUT)

The OCI environment handle initialized in object mode. See the description of OCIEnvCreate() and OCIInitialize() in Chapter 15 for more information.

err (IN/OUT)

The OCI error handle. If there is an error, it is recorded in err and this function returns OCI_ERROR. Obtain diagnostic information by calling OCIErrorGet().

ins (IN)

Pointer to an instance. The instance must be standalone, and if it is an object it must be pinned.

lock (OUT)

Return value for the lock status.

Comments

This function returns the lock status of an instance. If the instance is a value, this function always returns FALSE.

Related Functions

OCIObjectLock(), OCIObjectGetProperty()

OCI Miscellaneous Object Functions

This section describes the miscellaneous object functions.

Table 16-5 OCI Navigational Functions Quick Reference
Function/Page  Purpose 

OCIObjectCopy()  

Copy one instance to another  

OCIObjectGetAttr()  

Gets an object attribute  

OCIObjectGetInd()  

Get null structure of an instance  

OCIObjectGetObjectRef()  

Return reference to a given object  

OCIObjectGetTypeRef()  

Get a reference to a TDO of an instance  

OCIObjectLock()  

Lock a persistent object  

OCIObjectLockNoWait()  

Lock a persistent object but do not wait for the lock  

OCIObjectPin()  

Create a new instance  

OCIObjectSetAttr()  

Sets an object attribute  


OCIObjectCopy()

Purpose

Copies a source instance to a destination.

Syntax

sword OCIObjectCopy ( OCIEnv              *env,
                      OCIError            *err, 
                      CONST OCISvcCtx     *svc,
                      dvoid               *source, 
                      dvoid               *null_source, 
                      dvoid               *target, 
                      dvoid               *null_target, 
                      OCIType             *tdo,
                      OCIDuration         duration, 
                      ub1                 option );

Parameters

env (IN/OUT)

The OCI environment handle initialized in object mode. See the description of OCIEnvCreate() and OCIInitialize() in Chapter 15 for more information.

err (IN/OUT)

The OCI error handle. If there is an error, it is recorded in err and this function returns OCI_ERROR. Obtain diagnostic information by calling OCIErrorGet().

svc (IN)

An OCI service context handle, specifying the service context on which the copy operation is taking place

source (IN)

A pointer to the source instance; if it is an object, it must be pinned. See OCIObjectPin().

null_source (IN)

Pointer to the NULL structure of the source object.

target (IN)

A pointer to the target instance; if it is an object is must be pinned.

null_target (IN)

A pointer to the NULL structure of the target object.

tdo (IN)

The TDO for both the source and the target. Can be retrieved with OCIDescribeAny().

duration (IN)

Allocation duration of the target memory.

option (IN)

This parameter is currently unused. Pass as zero or OCI_DEFAULT.

Comments

This function copies the contents of the source instance to the target instance. This function performs a deep-copy such that all of the following is copied:

Memory is allocated with the duration specified in the duration parameter.

Certain data items are not copied:

The target or the containing instance of the target must be already have been created. This may be done with OCIObjectPin().

The source and target instances must be of the same type. If the source and target are located in a different databases, then the same type must exist in both databases.

Related Functions

OCIObjectPin()


OCIObjectGetAttr()

Purpose

Retrieves an object attribute.

Syntax

sword OCIObjectGetAttr ( OCIEnv             *env,
                         OCIError           *err,
                         dvoid              *instance, 
                         dvoid              *null_struct, 
                         struct OCIType     *tdo,
                         CONST text         **names, 
                         CONST ub4          *lengths, 
                         CONST ub4          name_count, 
                         CONST ub4          *indexes, 
                         CONST ub4          index_count, 
                         OCIInd             *attr_null_status, 
                         dvoid              **attr_null_struct, 
                         dvoid              **attr_value, 
                         struct OCIType     **attr_tdo );

Parameters

env (IN/OUT)

The OCI environment handle initialized in object mode. See the description of OCIEnvCreate() and OCIInitialize() in Chapter 15 for more information.

err (IN/OUT)

The OCI error handle. If there is an error, it is recorded in err and this function returns OCI_ERROR. Obtain diagnostic information by calling OCIErrorGet().

instance (IN)

Pointer to an object.

null_struct (IN)

The null structure of the object or array.

tdo (IN)

Pointer to the TDO.

names (IN)

Array of attribute names. This is used to specify the names of the attributes in the path expression.

lengths (IN)

Array of lengths of attribute names.

name_count (IN)

Number of element in the array names.

indexes (IN) [optional]

Not currently supported. Pass as (ub4 *)0.

index_count (IN) [optional]

Not currently supported. Pass as (ub4)0.

attr_null_status (OUT)

The null status of the attribute if the type of attribute is primitive.

attr_null_struct (OUT)

The null structure of an object or collection attribute.

attr_value (OUT)

Pointer to the attribute value.

attr_tdo (OUT)

Pointer to the TDO of the attribute.

Comments

This function gets a value from an object or from an array. If the parameter instance points to an object, then the path expression specifies the location of the attribute in the object. It is assumed that the object is pinned and that the value returned is valid until the object is unpinned.

Related Functions

OCIObjectSetAttr()


OCIObjectGetInd()

Purpose

Gets the NULL structure of a standalone instance.

Syntax

sword OCIObjectGetInd ( OCIEnv        *env, 
                        OCIError      *err, 
                        dvoid         *instance, 
                        dvoid         **null_struct );

Parameters

env (IN/OUT)

The OCI environment handle initialized in object mode. See the description of OCIEnvCreate() and OCIInitialize() in Chapter 15 for more information.

err (IN/OUT)

The OCI error handle. If there is an error, it is recorded in err and this function returns OCI_ERROR. Obtain diagnostic information by calling OCIErrorGet().

instance (IN)

A pointer to the instance whose NULL structure is being retrieved. The instance must be standalone. If instance is an object, it must already be pinned.

null_struct (OUT)

The NULL structure for the instance.

Comments

None.

Related Functions

OCIObjectPin()


OCIObjectGetObjectRef()

Purpose

Returns a reference to a given persistent object.

Syntax

sword OCIObjectGetObjectRef ( OCIEnv        *env, 
                              OCIError      *err,
                              dvoid         *object, 
                              OCIRef        *object_ref );

Parameters

env (IN/OUT)

The OCI environment handle initialized in object mode. See the description of OCIEnvCreate() and OCIInitialize() in Chapter 15 for more information.

err (IN/OUT)

The OCI error handle. If there is an error, it is recorded in err and this function returns OCI_ERROR. Obtain diagnostic information by calling OCIErrorGet().

object (IN)

Pointer to a persistent object. It must already be pinned.

object_ref (OUT)

A reference to the object specified in object. The reference must already be allocated. This can be accomplished with OCIObjectNew().

Comments

This function returns a reference to the given persistent object, given a pointer to the object. Passing a value (rather than an object) to this function causes an error.

See Also: For more information about object meta-attributes, see "Object Meta-Attributes".

Related Functions

OCIObjectPin(), OCIObjectPin()


OCIObjectGetTypeRef()

Purpose

Returns a reference to the type descriptor object (TDO) of a standalone instance.

Syntax

sword OCIObjectGetTypeRef ( OCIEnv        *env, 
                            OCIError      *err, 
                            dvoid         *instance, 
                            OCIRef        *type_ref );

Parameters

env (IN/OUT)

The OCI environment handle initialized in object mode. See the description of OCIEnvCreate() and OCIInitialize() in Chapter 15 for more information.

err (IN/OUT)

The OCI error handle. If there is an error, it is recorded in err and this function returns OCI_ERROR. Obtain diagnostic information by calling OCIErrorGet().

instance (IN)

A pointer to the standalone instance. It must be standalone, and if it is an object, it must already be pinned.

type_ref (OUT)

A reference to the type of the object. The reference must already be allocate. This can be accomplished with OCIObjectNew().

Comments

None.

Related Functions

OCIObjectPin(), OCIObjectPin()


OCIObjectLock()

Purpose

Locks a persistent object at the server.

Syntax

sword OCIObjectLock ( OCIEnv        *env, 
                      OCIError      *err, 
                      dvoid         *object );

Parameters

env (IN/OUT)

The OCI environment handle initialized in object mode. See the description of OCIEnvCreate() and OCIInitialize() in Chapter 15 for more information.

err (IN/OUT)

The OCI error handle. If there is an error, it is recorded in err and this function returns OCI_ERROR. Obtain diagnostic information by calling OCIErrorGet().

object (IN)

A pointer to the persistent object being locked. It must already be pinned.

Comments

This function will return an error for transient objects and values. It also returns an error if the object does not exist.

For more information about object locking, see "Locking Objects For Update".

Related Functions

OCIObjectPin(), OCIObjectIsLocked(), OCIObjectGetProperty(), OCIObjectLockNoWait()


OCIObjectLockNoWait()

Purpose

Locks a persistent object at the server but does not wait for the lock. and returns an error if the lock is unavailable.

Syntax

sword OCIObjectLockNoWait ( OCIEnv        *env, 
                            OCIError      *err, 
                            dvoid         *object );

Parameters

env (IN/OUT)

The OCI environment handle initialized in object mode. See the description of OCIEnvCreate() and OCIInitialize() in Chapter 15 for more information.

err (IN/OUT)

The OCI error handle. If there is an error, it is recorded in err and this function returns OCI_ERROR. Obtain diagnostic information by calling OCIErrorGet().

object (IN)

A pointer to the persistent object being locked. It must already be pinned.