Oracle Call Interface Programmer's Guide
Release 8.1.6

Part Number A76975-01

Library

Product

Contents

Index

Go to previous page Go to next page

18
OCI Cartridge Functions

The chapter contains the following sections:

Introduction

This chapter first describes the OCI external procedure functions. These functions enable users of external procedures to raise errors, allocate some memory, and get OCI context information. For more information about using these functions, seeOracle8i Data Cartridge Developer's Guide the Oracle8i Application Developer's Guide - Fundamentals.

Then the cartridge services functions are described. For more information about using these functions, see Oracle8i Data Cartridge Developer's Guide.

The Function Syntax

For each function, the following information is listed:

Purpose

A brief description of the action performed by the function.

Syntax

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

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. 

Comments

More 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.

Returns

A list of possible return values for the function.

Related Functions

A list of related function calls. For cartridge services, see all the other functions in the group being documented.

Return Codes

Success and error return codes are defined for certain external procedure interface functions. If a particular interface function returns OCIEXTPROC_SUCCESS or OCIEXTPROC_ERROR, then applications must use these macros to check for return values.

With_Context Type

The C callable interface to PL/SQL external procedures requires the with_context parameter to be passed. The type of this structure is OCIExtProcContext, which is opaque to the user.

The user can declare the with_context parameter in the application as

OCIExtProcContext *with_context;

Cartridge Services -- OCI External Procedures

The OCI external procedure functions for C:

Table 18-1 OCI External Procedure Functions Quick Reference  
Function/Page  Purpose 

OCIExtProcAllocCallMemory() 

Allocates memory for the duration of the External Procedure 

OCIExtProcRaiseExcp() 

Raises an Exception to PL/SQL 

OCIExtProcRaiseExcpWithMsg() 

Raises an exception with a message 

OCIExtProcGetEnv() 

Gets the OCI environment, service context, and error handles 


OCIExtProcAllocCallMemory()

Purpose

Allocate N bytes of memory for the duration of the External Procedure.

Syntax

dvoid * OCIExtProcAllocCallMemory ( OCIExtProcContext    *with_context,
                                    size_t                amount )

Parameters

with_context (IN)

The with_context pointer that is passed to the C External Procedure. See "With_Context Type".

amount (IN)

The number of bytes to allocate.

Comments

This call allocates amount bytes of memory for the duration of the call of the external procedure.

Any memory allocated by this call is freed by PL/SQL upon return from the external procedure. The application must not use any kind of free function on memory allocated by OCIExtProcAllocCallMemory(). Use this function to allocate memory for function returns.

A zero return value should be treated as an error

Returns

An untyped (opaque) Pointer to the allocated memory.

Example

text *ptr = (text *)OCIExtProcAllocCallMemory(wctx, 1024)

Related Functions

OCIErrorGet(), OCIMemoryAlloc().


OCIExtProcRaiseExcp()

Purpose

Raise an Exception to PL/SQL.

Syntax

size_t OCIExtProcRaiseExcp ( OCIExtProcContext    *with_context, 
                             int                   errnum )

Parameters

with_context (IN)

The with_context pointer that is passed to the C External Procedure. See "With_Context Type".

errnum (IN)

Oracle Error number to signal to PL/SQL. errnum must be a positive number and in the range 1 to 32767.

Comments

Calling this function signals an exception back to PL/SQL. After a successful return from this function, the external procedure must start its exit handling and return back to PL/SQL. Once an exception is signalled to PL/SQL, IN/OUT and OUT arguments, if any, are not processed at all.

Returns

This function returns OCIEXTPROC_SUCCESS if the call was successful. It returns OCIEXTPROC_ERROR if the call has failed.

Related Functions

OCIExtProcRaiseExcpWithMsg()


OCIExtProcRaiseExcpWithMsg()

Purpose

Raise an exception with a message.

Syntax

size_t OCIExtProcRaiseExcpWithMsg ( OCIExtProcContext   *with_context,
                                    int                  errnum, 
                                    char                 *errmsg, 
                                    size_t               msglen ) 

Parameters

with_context (IN)

The with_context pointer that is passed to the C External Procedure. See "With_Context Type".

errnum (IN)

Oracle Error number to signal to PL/SQL. The value of errnum must be a positive number and in the range 1 to 32767

errmsg (IN)

The error message associated with the errnum.

len (IN)

The length of the error message. Pass zero if errmsg is a null terminated string.

Comments

Raise an exception to PL/SQL. In addition, substitute the following error message string within the standard Oracle error message string. See the description of OCIExtProcRaiseExcp() for more information.

Returns

This function returns OCIEXTPROC_SUCCESS if the call was successful. It returns OCIEXTPROC_ERROR if the call has failed.

Related Functions

OCIExtProcRaiseExcp()


OCIExtProcGetEnv()

Purpose

Gets the OCI environment, service context, and error handles.

Syntax

sword OCIExtProcGetEnv ( OCIExtProcContext    *with_context, 
                         OCIEnv                envh, 
                         OCISvcCtx             svch, 
                         OCIError              errh )

Parameters

with_context (IN)

The with_context pointer that is passed to the C External Procedure. See "With_Context Type".

envh (OUT)

The OCI Environment handle.

svch (OUT)

The OCI Service handle.

errh (OUT)

The OCI Error handle.

Comments

The primary purpose of this function is to allow OCI callbacks to use the database in the same transaction. The OCI handles obtained by this function should be used in OCI callbacks to the database. If these handles are obtained through standard OCI calls, then these handles use a new connection to the database and cannot be used for callbacks in the same transaction. In one external procedure you can use either callbacks or a new connection, but not both.

Returns

This function returns OCI_SUCCESS if the call was successful; otherwise, it returns OCI_ERROR.

Related Functions

OCIEnvCreate(), OCIAttrGet(), OCIHandleAlloc()

Cartridge Services -- Memory Services

Table 18-2 OCI Parameter Manager Interface Functions Quick Reference  
Function/Page  Purpose 

OCIDurationBegin() 

Starts a user duration. 

OCIDurationEnd() 

Terminates a user duration. 

OCIMemoryAlloc() 

Allocates memory of a given size from a given duration. 

OCIMemoryResize() 

Resizes a memory chunk. 

OCIMemoryFree() 

Frees a memory chunk. 

For more information about using these functions, see Oracle8i Data Cartridge Developer's Guide.


OCIDurationBegin()

Purpose

Start a user duration

Syntax

sword OCIDurationBegin ( OCIEnv              *env,
                         OCIError            *err,
                         CONST OCISvcCtx     *svc, 
                         OCIDuration         parent,
                         OCIDuration         *duration );

Parameters

env (IN/OUT)

The OCI environment handle.

err (IN/OUT)

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

svc (IN)

The OCI service context handle. This should be passed as NULL for cartridge services.

parent (IN)

The duration number of the parent duration. One of these:

duration (OUT)

An identifier unique to the newly created user duration.

Comments

This function starts an user duration. A user can have multiple active user durations simultaneously. The user durations do not have to be nested. The duration parameter is used to return a number which uniquely identifies the duration created by this call.

Note that the environment and service context parameters cannot both be NULL.

Related Functions

OCIDurationEnd()


OCIDurationEnd()

Purpose

Terminates a user duration

Syntax

sword OCIDurationEnd ( OCIEnv             *env, 
                       OCIError           *err, 
                       CONST OCISvcCtx    *svc,
                       OCIDuration        duration,
                       CONST OCISvcCtx    *svc );

Parameters

env (IN/OUT)

The OCI environment handle.

err (IN/OUT)

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

duration (IN)

A user duration previously created by OCIDurationBegin().

svc (IN)

OCI service context (this should be passed as NULL for cartridge services, otherwise non-NULL)

Comments

This function terminates an user duration.

Note that the environment and service context parameters cannot both be NULL.

Related Functions

OCIDurationBegin()


OCIMemoryAlloc()

Purpose

This call allocates memory of a given size from a given duration.

Syntax

sword OCIMemoryAlloc( dvoid        *hndl, 
                      OCIError     *err, 
                      dvoid        **mem, 
                      OCIDuration  dur, 
                      ub4          size, 
                      ub4          flags);

Parameters

hndl (IN)

The OCI environment handle.

err (IN)

The error handle.

mem (OUT)

Memory allocated.

dur (IN)

One of the following (a previously created user duration):

OCI_DURATION_CALLOUT

OCI_DURATION_STATEMENT

OCI_DURATION_SESSION

OCI_DURATION_PROCESS

size (IN)

Size of memory to be allocated.

flags (IN)

Set OCI_MEMORY_CLEARED bit to get memory that has been cleared.

Comments

To allocate memory for duration of callout of agent, i.e., external procedure duration, use OCIExtProcAllocCallMemory() or OCIMemoryAlloc() with dur as OCI_DURATION_CALLOUT.

Returns

Error code.


OCIMemoryResize()

Purpose

This call resizes a memory chunk to a new size.

Syntax

sword OCIMemoryResize( dvoid        *hndl, 
                       OCIError     *err, 
                       dvoid        **mem, 
                       ub4          newsize, 
                       ub4          flags);

Parameters

hndl (IN)

The OCI environment or user session handle.

err (IN)

The error handle.

mem (IN/OUT)

Pointer to memory allocated previously using OCIMemoryAlloc().

newsize (IN)

Size of memory requested.

flags (IN)

Set OCI_MEMORY_CLEARED bit to get memory that has been cleared

Comments

Memory must have been allocated before this function can be called to resize.

Returns

Error code.


OCIMemoryFree()

Purpose

This call frees a memory chunk.

Syntax

sword OCIMemoryFree( dvoid    *hndl, 
                     OCIError *err, 
                     dvoid    *mem);

Parameters

hndl (IN)

The OCI environment or user session handle.

err (IN)

The error handle.

mem (IN/OUT)

Pointer to memory allocated previously using OCIMemoryAlloc().

Returns

Error code.

Cartridge Services -- Maintaining Context

Table 18-3 OCI Parameter Manager Interface Functions Quick Reference  
Function/Page  Purpose 

OCIContextSetValue() 

Save a value (or address) for a particular duration. 

OCIContextGetValue() 

Return the value stored in the context. 

OCIContextClearValue() 

Remove the value stored in the context. 

OCIContextGenerateKey() 

Returns a unique 4-byte value each time it is called. 

For more information about using these functions, see Oracle8i Data Cartridge Developer's Guide.


OCIContextSetValue()

Purpose

This call is used to save a value (or address) for a particular duration.

Syntax

sword OCIContextSetValue( dvoid       *hndl, 
                          OCIError    *err, 
                          OCIDuration duration, 
                          ub1         *key, 
                          ub1         keylen, 
                          dvoid       *ctx_value);

Parameters

hndl (IN)

The OCI environment or user session handle.

err (IN)

The error handle.

duration (IN)

One of the following (a previously created user duration):

OCI_DURATION_STATEMENT

OCI_DURATION_SESSION

key (IN)

Unique key value.

keylen (IN)

Length of the key. Maximum is 64 bits.

ctx_value (IN)

Pointer that will be saved in the context.

Comments

The context value being stored must be allocated out of memory of duration greater than or equal to the duration being passed in. The key being passed in should be unique in this session. Trying to save a context value under the same key and duration again will result in overwriting the old context value with the new one. Typically, a client will allocate a structure, store its address in the context using this call, and get this address in a separate call using OCIContextGetValue(). The (key, value) association can be explicitly removed by calling OCIContextClearValue() or else it will go away at the end of the duration.

Returns


OCIContextGetValue()

Purpose

This call is used to return the value that is stored in the context associated with the given key (by calling OCIContextSetValue()).

Syntax

sword OCIContextGetValue( dvoid      *hndl, 
                          OCIError   *err, 
                          ub1        *key, 
                          ub1        keylen, 
                          dvoid      **ctx_value);

Parameters

hndl (IN)

The OCI environment or user session handle.

err (IN)

The error handle.

key (IN)

Unique key value.

keylen (IN)

Length of the key. Maximum is 64 bits.

ctx_value (IN)

Pointer to the value stored in the context (NULL if no value was stored).

Comments

For ctx_value: a pointer to a preallocated pointer for the stored context to be returned is required.

Returns


OCIContextClearValue()

Purpose

This call is used to remove the value that is stored in the context associated with the given key (by calling OCIContextSetValue()).

Syntax

sword OCIContextClearValue( dvoid    *hndl, 
                            OCIError *err, 
                            ub1      *key, 
                            ub1      keylen);

Parameters

hndl (IN)

The OCI environment or user session handle.

err (IN)

The error handle.

key (IN)

Unique key value.

keylen (IN)

Length of the key. Maximum is 64 bits.

Comments

An error is returned when a non-existent key is passed.

Returns


OCIContextGenerateKey()

Purpose

This call will return a unique, 4-byte value each time it is called.

Syntax

sword OCIContextGenerateKey( dvoid    *hndl, 
                             OCIError *err, 
                             ub4      *key);

Parameters

hndl (IN)

The OCI environment or user session handle.

err (IN)

The error handle.

key (IN)

Unique key value.

keylen (IN)

Length of the key. Maximum is 64 bits.

Comments

This value is going to be unique on a per session basis.

Returns

Cartridge Services -- Parameter Manager Interface

Table 18-4 OCI Parameter Manager Interface Functions Quick Reference  
Function/Page  Purpose 

OCIExtractInit() 

Initializes the parameter manager. 

OCIExtractTerm() 

Releases all dynamically allocated storage. 

OCIExtractReset() 

Re-initializes memory. 

OCIExtractSetNumKeys() 

Informs the parameter manager of the number of keys that will be registered. 

OCIExtractSetKey() 

Registers information about a key with the parameter manager. 

OCIExtractFromFile() 

The keys and their values in the given file are processed. 

OCIExtractFromStr() 

The keys and the their values in the given string are processed. 

OCIExtractToInt() 

Gets the integer value for the specified key. 

OCIExtractToBool() 

Gets the boolean value for the specified key. 

OCIExtractToStr() 

Gets the string value for the specified key. 

OCIExtractToOCINum() 

Gets the number value for the specified key. 

OCIExtractToList() 

Generates a list of parameters from the parameter structures that are stored in memory. 

OCIExtractFromList() 

Generates a list of values for the parameter denoted by index in the parameter list. 

For more information about using these functions, see Oracle8i Data Cartridge Developer's Guide.


OCIExtractInit()

Purpose

This function initializes the parameter manager.

Syntax

sword OCIExtractInit( dvoid     *hndl, 
                      OCIError  *err)

Parameters

hndl (IN/OUT)

The OCI environment or user session handle.

err (IN/OUT)

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

Comments

This function must be called before calling any other parameter manager routine and it must only be called once. The NLS information is stored inside the parameter manager context and used in subsequent calls to OCIExtract routines.

Returns

OCI_SUCCESS,

OCI_INVALID_HANDLE,

OCI_ERROR.


OCIExtractTerm()

Purpose

This function releases all dynamically allocated storage.

Syntax

sword OCIExtractTerm( dvoid     *hndl, 
                      OCIError  *err);

Parameters

hndl (IN/OUT)

The OCI environment or user session handle.

err (IN/OUT)

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

Comments

This function may perform other internal bookkeeping functions. It must be called when the parameter manager is no longer being used and it must only be called once

Returns

OCI_SUCCESS,

OCI_INVALID_HANDLE,

OCI_ERROR.


OCIExtractReset()

Purpose

The memory currently used for parameter storage, key definition storage, and parameter value lists is freed and the structure is re-initialized.

Syntax

sword OCIExtractReset( dvoid     *hndl, 
                       OCIError  *err);

Parameters

hndl (IN/OUT)

The OCI environment or user session handle.

err (IN/OUT)

The OCI error handle; if there is an error, it is recorded in err and this function returns OCI_ERROR; diagnostic information can be obtained by calling OCIErrorGet().

Returns

OCI_SUCCESS,

OCI_INVALID_HANDLE,

OCI_ERROR.


OCIExtractSetNumKeys()

Purpose

Informs the parameter manager of the number of keys that will be registered.

Syntax

sword OCIExtractSetNumKeys( dvoid   *hndl, 
                            CIError *err, 
                            uword   numkeys);

Parameters

hndl (IN/OUT)

The OCI environment or user session handle.

err (IN/OUT)

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

numkeys (IN)

The number of keys that will be registered with OCIExtractSetKey().

Comments

This routine must be called prior to the first call of OCIExtractSetKey().

Returns

OCI_SUCCESS,

OCI_INVALID_HANDLE,

OCI_ERROR.


OCIExtractSetKey()

Purpose

Registers information about a key with the parameter manager.

Syntax

sword OCIExtractSetKey( dvoid       *hndl, 
                        OCIError    *err, 
                        CONST text  *name,
                        ub1         type, 
                        ub4         flag, 
                        CONST dvoid *defval, 
                        CONST sb4   *intrange, 
                        CONST text  *CONST *strlist);

Parameters

hndl (IN/OUT)

The OCI environment or user session handle.

err (IN/OUT)

The OCI error handle; if there is an error, it is recorded in err and this function returns OCI_ERROR; diagnostic information can be obtained by calling OCIErrorGet().

name (IN)

The name of the key.

type (IN)

The type of the key:

OCI_EXTRACT_TYPE_INTEGER,

OCI_EXTRACT_TYPE_OCINUM,

OCI_EXTRACT_TYPE_STRING,

OCI_EXTRACT_TYPE_BOOLEAN.

flag (IN)

Set to OCI_EXTRACT_MULTIPLE if the key can take multiple values or 0 otherwise.

defval (IN)

Set to the default value for the key. It may be NULL if there is no default. A string default must be a (text*) type, an integer default must be an (sb4*) type, and a boolean default must be a (ub1*) type.

intrange (IN)

Starting and ending values for the allowable range of integer values; may be NULL if the key is not an integer type or if all integer values are acceptable.

strlist (IN)

List of all acceptable text strings for the key ended with 0 (or NULL); may be NULL if the key is not a string type or if all text values are acceptable.

Comments

This routine must be called after calling OCIExtractNumKeys() and before calling OCIExtractFromFile() or OCIExtractFromString().

Returns

OCI_SUCCESS,

OCI_INVALID_HANDLE,

OCI_ERROR.


OCIExtractFromFile()

Purpose

The keys and their values in the given file are processed.

Syntax

sword OCIExtractFromFile( dvoid    *hndl, 
                          OCIError *err, 
                          ub4      flag, 
                          text     *filename);

Parameters

hndl (IN/OUT)

The OCI environment or user session handle.

err (IN/OUT)

The OCI error handle; if there is an error, it is recorded in err and this function returns OCI_ERROR; diagnostic information can be obtained by calling OCIErrorGet().

flag (IN)

Zero or has one or more of the following bits set:

OCI_EXTRACT_CASE_SENSITIVE,

OCI_EXTRACT_UNIQUE_ABBREVS,

OCI_EXTRACT_APPEND_VALUES.

filename (IN)

A null-terminated filename string.

Comments

OCIExtractSetNumKeys() and OCIExtractSetKey() routines must be called to define all of the keys before calling this routine.

Returns

OCI_SUCCESS,

OCI_INVALID_HANDLE,

OCI_ERROR.


OCIExtractFromStr()

Purpose

The keys and their values in the given string are processed.

Syntax

sword OCIExtractFromStr( dvoid    *hndl, 
                         OCIError *err, 
                         ub4      flag, 
                         text     *input);

Parameters

hndl (IN/OUT)

The OCI environment or user session handle.

err (IN/OUT)

The OCI error handle; if there is an error, it is recorded in err and this function returns OCI_ERROR; diagnostic information can be obtained by calling OCIErrorGet().

flag (IN)

Zero or has one or more of the following bits set:

OCI_EXTRACT_CASE_SENSITIVE,

OCI_EXTRACT_UNIQUE_ABBREVS,

or OCI_EXTRACT_APPEND_VALUES.

input (IN)

A null-terminated input string.

Comments

OCIExtractSetNumKeys() and OCIExtractSetKey() routines must be called to define all of the keys before calling this routine.

Returns

OCI_SUCCESS,

OCI_INVALID_HANDLE,

OCI_ERROR.


OCIExtractToInt()

Purpose

Gets the integer value for the specified key. The valno'th value (starting with 0) is returned.

Syntax

sword OCIExtractToInt( dvoid     *hndl, 
                       OCIError  *err, 
                       text      *keyname, 
                       uword     valno, 
                       sb4       *retval);

Parameters

hndl (IN)

The OCI environment or user session handle.

err (IN/OUT)

The OCI error handle; if there is an error, it is recorded in err and this function returns OCI_ERROR; diagnostic information can be obtained by calling OCIErrorGet().

keyname (IN)

Keyname (IN).

valno (IN)

Which value to get for this key.

retval (OUT)

The actual integer value.

Returns

OCI_SUCCESS,

OCI_INVALID_HANDLE,

OCI_NO_DATA,

OCI_ERROR.

OCI_NO_DATA means that there is no valno'th value for this key.


OCIExtractToBool()

Purpose

Gets the boolean value for the specified key. The valno'th value (starting with 0) is returned.

Syntax

sword OCIExtractToBool( dvoid     *hndl, 
                        OCIError  *err, 
                        text      *keyname, 
                        uword     valno, 
                        ub1       *retval);

Parameters

hndl (IN)

The OCI environment or user session handle.

err (IN/OUT)

The OCI error handle; if there is an error, it is recorded in err and this function returns OCI_ERROR; diagnostic information can be obtained by calling OCIErrorGet().

keyname (IN)

Key name.

valno (IN)

Which value to get for this key.

retval (OUT)

The actual boolean value.

Returns

OCI_SUCCESS,

OCI_INVALID_HANDLE,

OCI_NO_DATA,

OCI_ERROR.

OCI_NO_DATA means that there is no valno'th value for this key.


OCIExtractToStr()

Purpose

Gets the string value for the specified key. The valno'th value (starting with 0) is returned.

Syntax

sword OCIExtractToStr( dvoid *hndl, 
                       OCIError *err, 
                       text *keyname, 
                       uword valno, 
                       text *retval, 
                       uword buflen);

Parameters

hndl (IN)

The OCI environment or user session handle.

err (IN/OUT)

The OCI error handle; if there is an error, it is recorded in err and this function returns OCI_ERROR; diagnostic information can be obtained by calling OCIErrorGet().

keyname (IN)

Key name.

valno (IN)

Which value to get for this key.

retval (OUT)

The actual null-terminated string value.

buflen

The length of the buffer for retval.

Returns

OCI_SUCCESS,

OCI_INVALID_HANDLE,

OCI_NO_DATA,

OCI_ERROR.

OCI_NO_DATA means that there is no valno'th value for this key.


OCIExtractToOCINum()

Purpose

Gets the OCINumber value for the specified key. The valno'th value (starting with 0) is returned.

Syntax

sword OCIExtractToOCINum( dvoid     *hndl, 
                          OCIError  *err, 
                          text      *keyname, 
                          uword     valno, 
                          OCINumber *retval);

Parameters

hndl (IN)

The OCI environment or user session handle.

err (IN/OUT)

The OCI error handle; if there is an error, it is recorded in err and this function returns OCI_ERROR; diagnostic information can be obtained by calling OCIErrorGet().

keyname (IN)

Key name.

valno (IN)

Which value to get for this key.

retval (OUT)

The actual OCINumber value.

Returns

OCI_SUCCESS,

OCI_INVALID_HANDLE,

OCI_NO_DATA, or OCI_ERROR.

OCI_NO_DATA means that there is no valno'th value for this key.


OCIExtractToList()

Purpose

Generates a list of parameters from the parameter structures that are stored in memory. Must be called before OCIExtractValues() is called.

Syntax

sword OCIExtractToList( dvoid     *hndl,
                        OCIError  *err, 
                        uword      *numkeys);

Parameters

hndl (IN)

The OCI environment or user session handle.

err (IN/OUT)

The OCI error handle; if there is an error, it is recorded in err and this function returns OCI_ERROR; diagnostic information can be obtained by calling OCIErrorGet().

numkeys (OUT)

The number of distinct keys stored in memory.

Returns

OCI_SUCCESS,

OCI_INVALID_HANDLE,

OCI_ERROR.


OCIExtractFromList()

Purpose

Generates a list of values for the parameter denoted by index in the parameter list.

Syntax

sword OCIExtractFromList( dvoid       *hndl, 
                          OCIError    *err, 
                          uword       index, 
                          text        **name, 
                          ub1         *type, 
                          uword       *numvals, 
                          dvoid       ***values);

Parameters

hndl (IN)

The OCI environment or user session handle.

err (IN/OUT)

The OCI error handle; if there is an error, it is recorded in err and this function returns OCI_ERROR; diagnostic information can be obtained by calling OCIErrorGet().

index (IN)

Which parameter to retrieve from the parameter list.

name (OUT)

The name of the key for the current parameter.

type (OUT)

Type of the current parameter:

(OCI_EXTRACT_TYPE_STRING,

OCI_EXTRACT_TYPE_INTEGER,

OCI_EXTRACT_TYPE_OCINUM,

OCI_EXTRACT_TYPE_BOOLEAN).

numvals (OUT)

Number of values for this parameter.

values (OUT)

The values for this parameter.

Comments

OCIExtractToList() must be called prior to calling this routine to generate the parameter list from the parameter structures that are stored in memory.

Returns

OCI_SUCCESS,

OCI_INVALID_HANDLE,

OCI_ERROR.

Cartridge Services -- File I/O Interface

Table 18-5 OCI File I/O Interface Functions Quick Reference  
Function/Page  Purpose 

OCIFileInit() 

Initializes the OCIFile package. 

OCIFileTerm() 

Terminates the OCIFile package. 

OCIFileOpen() 

Opens a file. 

OCIFileClose() 

Closes a previously opened file. 

OCIFileRead() 

Reads from a file into a buffer. 

OCIFileWrite() 

Writes buflen bytes into the file. 

OCIFileSeek() 

Changes the current position in a file. 

OCIFileExists() 

Tests to see if the file exists. 

OCIFileGetLength() 

Gets the length of a file. 

OCIFileFlush() 

Writes buffered data to a file. 

For more information about using these functions, see Oracle8i Data Cartridge Developer's Guide.

OCIFileObject

The OCIFileObject data structure holds information about the way in which a file should be opened and the way in which it will be accessed once it has been opened. When this structure is initialized by OCIFileOpen(), it becomes an identifier through which operations can be performed on that file. It is a necessary parameter to every function that operates on open files. This data structure is opaque to OCIFile clients. It is initialized by OCIFileOpen() and terminated by OCIFileClose().


OCIFileInit()

Purpose

Initializes the OCIFile package. It must be called before any other OCIFile routine is called.

Syntax

sword OCIFileInit( dvoid    *hndl, 
                   OCIError *err);

Parameters

hndl (IN)

The OCI environment or user session handle.

err (IN/OUT)

The OCI error handle; if there is an error, it is recorded in err and this function returns OCI_ERROR; diagnostic information can be obtained by calling OCIErrorGet().

Returns

OCI_SUCCESS,

OCI_INVALID_HANDLE,

OCI_ERROR.


OCIFileTerm()

Purpose

Terminates the OCIFile package. It must be called after the OCIFile package is no longer being used.

Syntax

sword OCIFileTerm( dvoid    *hndl, 
                   OCIError *err);

Parameters

hndl (IN)

The OCI environment or user session handle.

err (IN/OUT)

The OCI error handle; if there is an error, it is recorded in err and this function returns OCI_ERROR; diagnostic information can be obtained by calling OCIErrorGet().

Returns

OCI_SUCCESS,

OCI_INVALID_HANDLE,

OCI_ERROR.


OCIFileOpen()

Purpose

Opens a file.

Syntax

sword OCIFileOpen( dvoid *hndl, 
                   OCIError       *err, 
                   OCIFileObject  **filep, 
                   OraText        *filename, 
                   OraText        *path, 
                   ub4            mode, 
                   ub4            create, 
                   ub4            type);

Parameters

hndl (IN)

The OCI environment or user session handle.

err (IN/OUT)

The OCI error handle; if there is an error, it is recorded in err and this function returns OCI_ERROR; diagnostic information can be obtained by calling OCIErrorGet().

filep (IN/OUT)

The file identifier.

filename (IN)

The file name as a null-terminated string.

path (IN)

The path of the file as a null-terminated string.

mode (IN)

The mode in which to open the file. Valid modes are

OCI_FILE_READ_ONLY,

OCI_FILE_WRITE_ONLY,

OCI_FILE_READ_WRITE.

create (IN)

Indicates if the file be created if it does not exist -- valid values are:

OCI_FILE_TRUNCATE -- create a file regardless of whether or not it exists. If the file already exists overwrite the existing file.

OCI_FILE_EXCL -- fail if the file exists, else create.

OCI_FILE_CREATE -- open the file if it exists, and create it if it does not.

OCI_FILE_APPEND -- set the file pointer to the end of the file prior to writing. This flag can be OR'ed with OCI_FILE_CREATE

type (IN)

File type. Valid values are

OCI_FILE_TEXT,

OCI_FILE_BIN,

OCI_FILE_STDIN,

OCI_FILE_STDOUT,

OCI_FILE_STDERR.

Returns

OCI_SUCCESS,

OCI_INVALID_HANDLE,

OCI_ERROR.


OCIFileClose()

Purpose

Closes a previously opened file.

Syntax

sword OCIFileClose( dvoid         *hndl, 
                    OCIError      *err, 
                    OCIFileObject *filep);

Parameters

hndl (IN)

The OCI environment or user session handle.

err (IN/OUT)

The OCI error handle; if there is an error, it is recorded in err and this function returns OCI_ERROR; diagnostic information can be obtained by calling OCIErrorGet().

filep (IN/OUT)

A pointer to a file identifier to be closed.

Comments

Once this returns, the OCIFileObject structure pointed to by filep will have been destroyed. Therefore, you should not attempt to access this structure after this returns.

Returns

OCI_SUCCESS,

OCI_INVALID_HANDLE,

OCI_ERROR.


OCIFileRead()

Purpose

Reads from a file into a buffer.

Syntax

sword OCIFileRead( dvoid         *hndl, 
                   OCIError      *err, 
                   OCIFileObject *filep, 
                   dvoid         *bufp, 
                   ub4           bufl, 
                   ub4           *bytesread);

Parameters

hndl (IN)

The OCI environment or user session handle.

err (IN/OUT)

The OCI error handle; if there is an error, it is recorded in err and this function returns OCI_ERROR; diagnostic information can be obtained by calling OCIErrorGet().

filep (IN/OUT)

A file identifier that uniquely references the file.

bufp(IN)

The pointer to a buffer into which the data will be read. The length of the allocated memory is assumed to be bufl.

bufl (IN)

The length of the buffer in bytes.

bytesread (OUT)

The number of bytes read.

Comments

As many bytes as possible will be read into the user buffer. The read will end either when the user buffer is full, or when it reaches end-of-file.

Returns

OCI_SUCCESS,

OCI_INVALID_HANDLE,

OCI_ERROR.


OCIFileWrite()

Purpose

Writes buflen bytes into the file.

Syntax

sword OCIFileWrite( dvoid         *hndl, 
                    OCIError      *err, 
                    OCIFileObject *filep, 
                    dvoid         *bufp, 
                    ub4           buflen, 
                    ub4           *byteswritten);

Parameters

hndl (IN)

The OCI environment or user session handle.

err (IN/OUT)

The OCI error handle; if there is an error, it is recorded in err and this function returns OCI_ERROR; diagnostic information can be obtained by calling OCIErrorGet().

filep (IN/OUT)

A file identifier that uniquely references the file.

bufp(IN)

The pointer to a buffer from into which the data will be written. The length of the allocated memory is assumed to be buflen.

buflen (IN)

The length of the buffer in bytes.

bytesread (OUT)

The number of bytes written.

Returns

OCI_SUCCESS,

OCI_INVALID_HANDLE,

OCI_ERROR.


OCIFileSeek()

Purpose

Changes the current position in a file.

Syntax

sword OCIFileSeek( dvoid         *hndl, 
                   OCIError      *err, 
                   OCIFileObject *filep, 
                   uword         origin, 
                   ubig_ora      offset, 
                   sb1           dir);

Parameters

hndl (IN)

The OCI environment or user session handle.

err (IN/OUT)

The OCI error handle; if there is an error, it is recorded in err and this function returns OCI_ERROR; diagnostic information can be obtained by calling OCIErrorGet().

filep (IN/OUT)

A file identifier that uniquely references the file.

origin(IN)

The starting point we want to seek from. The starting point may be

OCI_FILE_SEEK_BEGINNING (beginning),

OCI_FILE_SEEK_CURRENT (current position),

OCI_FILE_SEEK_END (end of file).

offset (IN)

The number of bytes from the origin you want to start reading from.

dir (IN)

The direction to go from the origin.

NOTE: The direction can be either OCIFILE_FORWARD or OCIFILE_BACKWARD.

Comments

This will allow a seek past the end of the file. Reading from such a position will cause an end-of-file condition to be reported. Writing to such a position will not work on all file systems. This is because some systems do not allow files to grow dynamically. They require that files be preallocated with a fixed size. Note that this function performs a seek to a byte location.

Returns

OCI_SUCCESS,

OCI_INVALID_HANDLE,

OCI_ERROR.


OCIFileExists()

Purpose

Tests to see if the file exists.

Syntax

sword OCIFileExists( dvoid    *hndl, 
                     OCIError *err, 
                     OraText  *filename, 
                     OraText  *path, 
                     ub1      *flag);

Parameters

hndl (IN)

The OCI environment or user session handle.

err (IN/OUT)

The OCI error handle; if there is an error, it is recorded in err and this function returns OCI_ERROR; diagnostic information can be obtained by calling OCIErrorGet().

filename (IN)

The file name as a null-terminated string.

path (IN)

The path of the file as a null-terminated string.

flag (OUT)

Set to TRUE if the file exists or FALSE if it does not.

Returns

OCI_SUCCESS,

OCI_INVALID_HANDLE,

OCI_ERROR.


OCIFileGetLength()

Purpose

Gets the length of a file.

Syntax

sword OCIFileGetLength( dvoid    *hndl, 
                        OCIError *err, 
                        OraText  *filename, 
                        OraText  *path, 
                        ubig_ora *lenp);

Parameters

hndl (IN)

The OCI environment or user session handle.

err (IN/OUT)

The OCI error handle; if there is an error, it is recorded in err and this function returns OCI_ERROR; diagnostic information can be obtained by calling OCIErrorGet().

filename (IN)

The file name as a null-terminated string.

path (IN)

The path of the file as a null-terminated string.

lenp (OUT)

Set to the length of the file in bytes.

Returns

OCI_SUCCESS,

OCI_INVALID_HANDLE,

OCI_ERROR.


OCIFileFlush()

Purpose

Writes buffered data to a file.

Syntax

sword OCIFileFlush( dvoid         *h
                    OCIError      *err, 
                    OCIFileObject *filep);

Parameters

hndl (IN)

The OCI environment or user session handle.

err (IN/OUT)

The OCI error handle; if there is an error, it is recorded in err and this function returns OCI_ERROR; diagnostic information can be obtained by calling OCIErrorGet().

filep (IN/OUT)

A file identifier that uniquely references the file.

Returns

OCI_SUCCESS,

OCI_INVALID_HANDLE,

OCI_ERROR.

Cartridge Services -- String Formatting Interface

Table 18-6 String Formatting Functions Quick Reference  
Function/Page  Purpose 

OCIFormatInit() 

Initializes the OCIFormat package. 

OCIFormatTerm() 

Terminates the OCIFormat package. 

OCIFormatString() 

Writes a text string into the supplied text buffer. 

For more information about using these functions, see Oracle8i Data Cartridge Developer's Guide.


OCIFormatInit()

Purpose

Initializes the OCIFormat package.

Syntax

sword OCIFormatInit( dvoid     *hndl, 
                     OCIError  *err)

Parameters

hndl (IN)

The OCI environment or user session handle.

err (IN/OUT)

The OCI error handle; if there is an error, it is recorded in err and this function returns OCI_ERROR; diagnostic information can be obtained by calling OCIErrorGet().

Comments

This routine must be called before calling any other OCIFormat routine and it must only be called once.

Returns

OCI_SUCCESS,

OCI_INVALID_HANDLE,

OCI_ERROR.


OCIFormatTerm()

Purpose

Terminates the OCIFormat package.

Syntax

sword OCIFormatTerm( dvoid    *hndl, 
                     OCIError *err)

Parameters

hndl (IN)

The OCI environment or user session handle.

err (IN/OUT)

The OCI error handle; if there is an error, it is recorded in err and this function returns OCI_ERROR; diagnostic information can be obtained by calling OCIErrorGet().

Comments

This function must be called after the OCIFormat package is no longer being used and it must only be called once.

Returns

OCI_SUCCESS,

OCI_INVALID_HANDLE,

OCI_ERROR.


OCIFormatString()

Purpose

Writes a text string into the supplied text buffer using the argument list submitted to it and in accordance with the format string given.

Syntax

sword OCIFormatString( dvoid        *hndl, 
                       OCIError     *err, 
                       text         *buffer, 
                       sbig_ora     bufferLength, 
                       sbig_ora     *returnLength, 
                       CONST text   *formatString,...);

Parameters

hndl (IN)

The OCI environment or user session handle.

err (IN/OUT)

The OCI error handle; if there is an error, it is recorded in err and this function returns OCI_ERROR; diagnostic information can be obtained by calling OCIErrorGet().

buffer (OUT)

The buffer that contains the string.

bufferLength (IN)

The length of the buffer in bytes.

returnLength (OUT)

The number of bytes written to the buffer (excluding the terminating null).

formatString (IN)

The format string which can be any combination of literal text and format specifications. A format specification is delimited by the '%' character and is followed by any number (including none) of optional format modifiers and terminated by a mandatory format code. If the format string ends with '%', i.e. with no format modifiers or format specifier following it, then no action is taken. The format modifiers and format codes available are described in the tables that follow.

...(IN)

Variable number of arguments of the form <OCIFormat type wrapper>(<variable>) where <variable> must be a variable containing the value to be used. No constant values or expressions are allowed as arguments to the OCIFormat type wrappers; The OCIFormat type wrappers that are available are listed below. The argument list must be terminated with OCIFormatEnd.

OCIFormatUb1(ub1 variable);

OCIFormatUb2(ub2 variable);

OCIFormatUb4(ub4 variable);

OCIFormatUword(uword variable);

OCIFormatUbig_ora(ubig_ora variable);

OCIFormatSb1(sb1 variable);

OCIFormatSb2(sb2 variable);

OCIFormatSb4(sb4 variable);

OCIFormatSword(sword variable);

OCIFormatSbig_ora(sbig_ora variable);

OCIFormatEb1(eb1 variable);

OCIFormatEb2(eb2 variable);

OCIFormatEb4(eb4 variable);

OCIFormatEword(eword variable);

OCIFormatChar (text variable);

OCIFormatText(CONST text *variable);

OCIFormatDouble(double variable);

OCIFormatDvoid(CONST dvoid *variable);

OCIFormatEnd

Comments

The first call to this routine must be preceded by a call to the OCIFormatInit routine that initializes the OCIFormat package for use. When this routine is no longer needed terminate the OCIFormat package by a call to the OCIFormatTerm routine.

Returns

OCI_SUCCESS,

OCI_INVALID_HANDLE,

OCI_ERROR.


Format Modifiers

A format modifier alters or extends the format specification, allowing more specialized output. The format modifiers may be in any order and are all optional.

Flags (in any order)

Flag  Operation 

'-' 

left-justify the output in the field 

'+' 

always print a sign ('+' or '-') for numeric types 

' ' 

if a number's sign is not printed then print a space in the sign position 

'0' 

pad numeric output with zeros not spaces  

Alternate output:
Field Width

<w> where <w> is a number specifying a minimum field width. The converted argument will be printed in a field at least this wide, and wider if necessary. If the converted argument takes up fewer display positions than the field width, it will be padded on the left (or right for left justification) to make up the field width. The padding character is normally a space, but it is a zero if the zero padding flag was specified. The special character '*' may be used in place of <w> and indicates the current argument is to be used for the field width value, the actual field or precision follows as the next sequential argument.

Precision

.<p> specifies a period followed by the number <p>, specifying the maximum number of display positions to print from a string, or digits after the radix point for a decimal number, or the minimum number of digits to print for an integer type (leading zeroes will be added to make up the difference). The special character '*' may be used in place of <p> indicating the current argument contains the precision value.

Argument Index

(<n>) where <n> is an integer index into the argument list with the first argument being 1. If no argument index is specified in a format specification the first argument is selected. The next time no argument index is specified in a format specification the second argument is selected and so on. Format specifications with and without argument indexes can be in any order and are independent of each other in operation.

For example, the format string "%u %(4)u %u %(2)u %u" selects the first, fourth, second, second, and third arguments given to OCIFormatString().


Format Codes

A format code specifies how to format an argument that is being written to a string.

Note that these codes can appear in upper case, which will cause all alphabetic characters in the output to appear in upper case except for text strings, which are not converted.

Codes  Operation 

'c' 

single-byte character in the compiler character set 

'd' 

signed decimal integer 

'e' 

exponential (scientific) notation of the form [-]<d><r>[<d>...]e+[<d>]<d><d> where <r> is the radix character for the current language and <d> is any single digit; the default precision is given by the constant OCIFormatDP. the precision may be optionally specified as a format modifier - using a precision of 0 suppresses the radix character; the exponent is always printed in at least 2 digits, and can take up to 3 e.g. 1e+01, 1e+10, and 1e+100 

'f' 

fixed decimal notation of the form [-]<d>[<d>...]<r>[<d>...] where <r> is the appropriate radix character for the current language and <d> is any single digit; the precision may be optionally specified as a format modifier- using a precision of 0 suppresses the radix character. the default precision is given by the constant OCIFormatDP 

'g' 

variable floating-point notation; chooses 'e' or 'f', selecting 'f'' if the number will fit in the specified precision (default precision if unspecified), and choosing 'e' only if exponential format will allow more significant digits to be printed; does not print a radix character if number has no fractional part 

'i' 

identical to 'd' 

'o' 

unsigned octal integer 

'p' 

platform specific pointer printout 

's' 

prints an argument using the default format code for its type:

ociformatub<n>, ociformatuword, ociformatubig_ora, ociformateb<n>, and ociformateword.

the format code used is 'u'.

ociformatsb<n>, ociformatsword, and ociformatsbig_ora.

the format code used is 'd'.

ociformatchar

the format code used is 'c'.

ociformattext

prints text until trailing null is found.

ociformatdouble

the format code used is 'g'.

ociformatdvoid

the format code used is 'p'.

' %' - print a '%'.

 

'u' 

unsigned decimal integer 

'x' 

unsigned hexadecimal integer 


Example

/* This example shows the power of arbitrary argument    */
/* selection in the context of internationalization.  A  */
/* date is formatted in 2 different ways for 2 different */
/* countries according to the format string yet the      */
/* argument list submitted to OCIFormatString remains    */
/* invariant.                                            */

text      buffer[255];
ub1       day, month, year;
OCIError *err;
dvoid    *hndl;

/* Set the date. */

day   = 10;
month = 3;
year  = 97;

/* Work out the date in United States' style: mm/dd/yy *:/
OCIFormatString(hndl, err,
                buffer, (sbig_ora)sizeof(buffer),
                (CONST text *)"%(2)02u/%(1)02u/%(3)02u",
                OCIFormatUb1(day),
                OCIFormatUb1(month),
                OCIFormatUb1(year),
                OCIFormatEnd);    /* Buffer is "03/10/97". */

/* Work out the date in New Zealand style: dd/mm/yy *:/
OCIFormatString(hndl, err,
                buffer, (sbig_ora)sizeof(buffer),
                (CONST text *)"%(1)02u/%(2)02u/%(3)02u",
                OCIFormatUb1(day),
                OCIFormatUb1(month),
                OCIFormatUb1(year),
                OCIFormatEnd);    /* Buffer is "10/03/97". */

Go to previous page Go to next page
Oracle
Copyright © 1996-2000, Oracle Corporation.

All Rights Reserved.

Library

Product

Contents

Index