Oracle8i Data Cartridge Developer's Guide Release 8.1.5 A68002-01 |
|
This reference chapter includes the following information:
dvoid * OCIExtProcAllocCallMemory ( OCIExtProcContext *with_context, size_t amount )
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
An untyped (opaque) Pointer to the allocated memory.
Keyword/Parameter | Meaning |
---|---|
|
the with_context pointer that is passed to the C External Procedure |
|
the number of bytes to allocate |
text *ptr = (text *)OCIExtProcAllocCallMemory(wctx, 1024)
size_t OCIExtProcRaiseExcp ( OCIExtProcContext *with_context, int errnum )
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.
OCIEXTPROC_SUCCESS
- If the call was successful.
OCIEXTPROC_ERROR
- If the call failed.
Table 13-2 OCIExtProcAllocCallMemory Keywords/Parameters
size_t OCIExtProcRaiseExcpWithMsg ( OCIExtProcContext *with_context, int errnum, char *errmsg, size_t msglen )
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.
OCIEXTPROC_SUCCESS
if the call was successful.
OCIEXTPROC_ERROR
if the call failed.
sword OCIDurationBegin(OCIEnv *env, OCIError *err, CONST OCISvcCtx *svc, OCIDuration parent, OCIDuration *dur);
This call starts a user duration. Note that the environment or service context parameter cannot both be NULL
.
An error code.
sword OCIDurationEnd(OCIEnv *env, OCIError *err, OCIDuration dur, CONST OCISvcCtx *svc);
This call terminates a user duration. All memory allocated for this duration is freed. Note that the environment or service context parameter cannot both be NULL
.
Error code.
sword OCIMemoryAlloc(dvoid *hndl, OCIError *err, dvoid **mem, OCIDuration dur, ub4 size, ub4 flags);
This call allocates memory of a given size from a given duration. To allocate memory for duration of callout of agent, i.e., external procedure duration, use OCIExtProcAllocCallMemory
. If the hndl
is an OCI environment, the only duration supported is OCI_DURATION_PROCESS
. If the hndl
is an OCI user session, the duration cannot be OCI_DURATION_PROCESS
.
Error code.
sword OCIMemoryResize(dvoid *hndl, OCIError *err, dvoid **mem, ub4 newsize, ub4 flags);
This call resizes a memory chunk to a new size. Memory must have been allocated before this function can be called to resize.
Error code.
sword OCIMemoryFree(dvoid *hndl, OCIError *err, dvoid *mem);
This call frees a memory chunk.
Error code.
Keyword/Parameter | Meaning |
---|---|
|
the |
|
the error handle |
|
pointer to a previously allocated memory |
sword OCIContextSetValue(dvoid *hndl, OCIError *err, OCIDuration duration, ub1 *key, ub1 keylen, dvoid *ctx_value);
This call can be used to save a value (or address) for a particular duration. 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.
OCI_SUCCESS
.
OCI_ERROR
.
Table 13-9 OCIContextSetValue Keywords/Parameters
sword OCIContextGetValue(dvoid *hndl, OCIError *err, ub1 *key, ub1 keylen, dvoid **ctx_value);
This call is used to return the value that is stored in the context associated with the given key (by calling OCIContextSetValue
()).
ctx_value
-- pointer to a preallocated pointer for the stored context to be returned
OCI_SUCCESS
.
OCI_ERROR
.
Table 13-10 OCIContextSetValue Keywords/Parameters
sword OCIContextClearValue(dvoid *hndl, OCIError *err, ub1 *key, ub1 keylen);
This call is used to remove the value that is stored in the context associated with the given key (by calling OCIContextSetValue()). An error is returned when a non-existent key is passed.
OCI_SUCCESS
.
OCI_ERROR
.
Table 13-11 OCIContextClearValue Keywords/Parameters
Keyword/Parameter | Meaning |
---|---|
|
the |
|
the error handle |
|
unique key value |
|
length of the above key (maximum length is 64 bits) |
sword OCIContextGenerateKey(dvoid *hndl, OCIError *err, ub4 *key);
This call will return a unique, 4 byte value each time it is called. This value is going to be unique on a per session basis.
OCI_SUCCESS
.
OCI_ERROR
.
Table 13-12 OCIContextGenerateKey Keywords/Parameters
Keyword/Parameter | Meaning |
---|---|
|
the |
|
the error handle |
|
pointer to a unique, 4 byte value |
sword OCIExtractInit(dvoid *hndl, OCIError *err)
This function initializes the parameter manager. It 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.
OCI_SUCCESS
, OCI_INVALID_HANDLE
, or OCI_ERROR.
sword OCIExtractTerm(dvoid *hndl, OCIError *err);
This function releases all dynamically allocated storage and 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.
OCI_SUCCESS
, OCI_INVALID_HANDLE
, or OCI_ERROR.
sword OCIExtractReset(dvoid *hndl, OCIError *err);
The memory currently used for parameter storage, key definition storage, and parameter value lists is freed and the structure is reinitialized.
OCI_SUCCESS
, OCI_INVALID_HANDLE
, or OCI_ERROR.
sword OCIExtractSetNumKeys(dvoid *hndl, OCIError *err, uword numkeys);
Informs the parameter manager of the number of keys that will be registered. This routine must be called prior to the first call of OCIExtractSetKey
().
OCI_SUCCESS
, OCI_INVALID_HANDLE
, or OCI_ERROR.
sword OCIExtractSetKey(dvoid *hndl, OCIError *err, CONST text *name, ub1 type, ub4 flag, CONST dvoid *defval, CONST sb4 *intrange, CONST text *CONST *strlist);
Registers information about a key with the parameter manager. This routine must be called after calling OCIExtractNumKeys
() and before calling OCIExtractFromFile
() or OCIExtractFromString
().
OCI_SUCCESS
, OCI_INVALID_HANDLE
, or OCI_ERROR.
sword OCIExtractFromFile(dvoid *hndl, OCIError *err, ub4 flag, text *filename);
The keys and their values in the given file are processed. OCIExtractSetNumKeys
() and OCIExtractSetKey
() routines must be called to define all of the keys before calling this routine.
OCI_SUCCESS
, OCI_INVALID_HANDLE
, or OCI_ERROR.
sword OCIExtractFromStr(dvoid *hndl, OCIError *err, ub4 flag, text *input);
The keys and their values in the given string are processed. OCIExtractSetNumKeys
() and OCIExtractSetKey
() routines must be called to define all of the keys before calling this routine.
OCI_SUCCESS
, OCI_INVALID_HANDLE
, or OCI_ERROR.
sword OCIExtractToInt(dvoid *hndl, OCIError *err, text *keyname, uword valno, sb4 *retval);
Gets the integer value for the specified key. The valno
'th value (starting with 0) is returned.
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.
sword OCIExtractToBool(dvoid *hndl, OCIError *err, text *keyname, uword valno, ub1 *retval);
Gets the boolean value for the specified key. The valno
'th value (starting with 0) is returned.
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.
sword OCIExtractToStr(dvoid *hndl, OCIError *err, text *keyname, uword valno, text *retval, uword buflen);
Gets the string value for the specified key. The valno
'th value (starting with 0) is returned.
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.
sword OCIExtractToOCINum(dvoid *hndl, OCIError *err, text *keyname, uword valno, OCINumber *retval);
Gets the OCINumber value for the specified key. The valno
'th value (starting with 0) is returned.
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.
sword OCIExtractToList(dvoid *hndl, OCIError *err, uword *numkeys);
Generates a list of parameters from the parameter structures that are stored in memory. Must be called before OCIExtractValues
() is called.
OCI_SUCCESS
, OCI_INVALID_HANDLE
, or OCI_ERROR.
sword OCIExtractFromList(dvoid *hndl, OCIError *err, uword index, text **name, ub1 *type, uword *numvals, dvoid ***values);
Generates a list of values for the parameter denoted by index
in the parameter list. OCIExtractToList
() must be called prior to calling this routine to generate the parameter list from the parameter structures that are stored in memory.
OCI_SUCCESS
, OCI_INVALID_HANDLE
, or OCI_ERROR.
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
().
sword OCIFileInit(dvoid *hndl, OCIError *err);
Initializes the OCIFile
package. It must be called before any other OCIFile
routine is called.
OCI_SUCCESS
, OCI_INVALID_HANDLE
, or OCI_ERROR.
sword OCIFileTerm(dvoid *hndl, OCIError *err);
Terminates the OCIFile
package. It must be called after the OCIFile
package is no longer being used.
OCI_SUCCESS
, OCI_INVALID_HANDLE
, or OCI_ERROR.
sword OCIFileOpen(dvoid *hndl, OCIError *err, OCIFileObject **filep, OraText *filename, OraText *path, ub4 mode, ub4 create, ub4 type);
Opens a file.
OCI_SUCCESS
, OCI_INVALID_HANDLE
, or OCI_ERROR.
sword OCIFileClose(dvoid *hndl, OCIError *err, OCIFileObject *filep);
Closes a previously opened file. 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.
OCI_SUCCESS
, OCI_INVALID_HANDLE
, or OCI_ERROR.
sword OCIFileRead(dvoid *hndl, OCIError *err, OCIFileObject *filep, dvoid *bufp, ub4 bufl, ub4 *bytesread);
Reads from a file into a buffer. 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.
OCI_SUCCESS
, OCI_INVALID_HANDLE
, or OCI_ERROR.
sword OCIFileWrite(dvoid *hndl, OCIError *err, OCIFileObject *filep, dvoid *bufp, ub4 buflen, ub4 *byteswritten);
Writes buflen bytes into the file.
OCI_SUCCESS
, OCI_INVALID_HANDLE
, or OCI_ERROR.
sword OCIFileSeek(dvoid *hndl, OCIError *err, OCIFileObject *filep, uword origin, ubig_ora offset, sb1 dir);
Changes the current position in a file. 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.
OCI_SUCCESS
, OCI_INVALID_HANDLE
, or OCI_ERROR.
sword OCIFileExists(dvoid *hndl, OCIError *err, OraText *filename, OraText *path, ub1 *flag);
Tests to see if the file exists.
OCI_SUCCESS
, OCI_INVALID_HANDLE
, or OCI_ERROR.
sword OCIFileGetLength(dvoid *hndl, OCIError *err, OraText *filename, OraText *path, ubig_ora *lenp);
Gets the length of a file.
OCI_SUCCESS
, OCI_INVALID_HANDLE
, or OCI_ERROR.
sword OCIFileFlush(dvoid *hndl, OCIError *err, OCIFileObject *filep);
Write buffered data to a file.
OCI_SUCCESS
, OCI_INVALID_HANDLE
, or OCI_ERROR.
sword OCIFormatInit(dvoid *hndl, OCIError *err)
Initializes the OCIFormat
package. This routine must be called before calling any other OCIFormat
routine and it must only be called once.
OCI_SUCCESS
, OCI_INVALID_HANDLE
, or OCI_ERROR.
sword OCIFormatTerm(dvoid *hndl, OCIError *err)
Terminates the OCIFormat
package. It must be called after the OCIFormat
package is no longer being used and it must only be called once.
OCI_SUCCESS
, OCI_INVALID_HANDLE
, or OCI_ERROR.
sword OCIFormatString(dvoid *hndl, OCIError *err, text *buffer, sbig_ora bufferLength, sbig_ora *returnLength, CONST text *formatString,...);
Writes a text string into the supplied text buffer using the argument list submitted to it and in accordance with the format string given. 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.
OCI_SUCCESS
, OCI_INVALID_HANDLE
, or OCI_ERROR.
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.
'+'
and ' '
flags are used in the same format specification then the ' '
flag is ignored.
'-'
and '0'
flags are used in the same format specification then the '-'
flag is ignored.
<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.
.<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.
(<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
.
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.
/* 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". */