Oracle 8i Data Cartridge Developer's Guide Release 2 (8.1.6) Part Number A76937-01 |
|
Reference: Cartridge Services Using C, 6 of 6
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().
Initializes the OCIFile package. It must be called before any other OCIFile routine is called.
sword OCIFileInit( dvoid *hndl, OCIError *err);
The OCI environment or user session handle.
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().
OCI_SUCCESS,
OCI_INVALID_HANDLE,
OCI_ERROR.
Terminates the OCIFile package. It must be called after the OCIFile package is no longer being used.
sword OCIFileTerm( dvoid *hndl, OCIError *err);
The OCI environment or user session handle.
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().
OCI_SUCCESS,
OCI_INVALID_HANDLE,
OCI_ERROR.
Opens a file.
sword OCIFileOpen( dvoid *hndl, OCIError *err, OCIFileObject **filep, OraText *filename, OraText *path, ub4 mode, ub4 create, ub4 type);
The OCI environment or user session handle.
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().
The file identifier.
The file name as a null-terminated string.
The path of the file as a null-terminated string.
The mode in which to open the file. Valid modes are
OCI_FILE_READ_ONLY,
OCI_FILE_WRITE_ONLY,
OCI_FILE_READ_WRITE.
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
File type. Valid values are
OCI_FILE_TEXT,
OCI_FILE_BIN,
OCI_FILE_STDIN,
OCI_FILE_STDOUT,
OCI_FILE_STDERR.
OCI_SUCCESS,
OCI_INVALID_HANDLE,
OCI_ERROR.
Closes a previously opened file.
sword OCIFileClose( dvoid *hndl, OCIError *err, OCIFileObject *filep);
The OCI environment or user session handle.
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().
A pointer to a file identifier to be closed.
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,
OCI_ERROR.
Reads from a file into a buffer.
sword OCIFileRead( dvoid *hndl, OCIError *err, OCIFileObject *filep, dvoid *bufp, ub4 bufl, ub4 *bytesread);
The OCI environment or user session handle.
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().
A file identifier that uniquely references the file.
The pointer to a buffer into which the data will be read. The length of the allocated memory is assumed to be bufl.
The length of the buffer in bytes.
The number of bytes read.
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,
OCI_ERROR.
Writes buflen bytes into the file.
sword OCIFileWrite( dvoid *hndl, OCIError *err, OCIFileObject *filep, dvoid *bufp, ub4 buflen, ub4 *byteswritten);
The OCI environment or user session handle.
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().
A file identifier that uniquely references the file.
The pointer to a buffer from into which the data will be written. The length of the allocated memory is assumed to be buflen.
The length of the buffer in bytes.
The number of bytes written.
OCI_SUCCESS,
OCI_INVALID_HANDLE,
OCI_ERROR.
Changes the current position in a file.
sword OCIFileSeek( dvoid *hndl, OCIError *err, OCIFileObject *filep, uword origin, ubig_ora offset, sb1 dir);
The OCI environment or user session handle.
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().
A file identifier that uniquely references the file.
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).
The number of bytes from the origin you want to start reading from.
The direction to go from the origin.
NOTE: The direction can be either OCIFILE_FORWARD or OCIFILE_BACKWARD.
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,
OCI_ERROR.
Tests to see if the file exists.
sword OCIFileExists( dvoid *hndl, OCIError *err, OraText *filename, OraText *path, ub1 *flag);
The OCI environment or user session handle.
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().
The file name as a null-terminated string.
The path of the file as a null-terminated string.
Set to TRUE if the file exists or FALSE if it does not.
OCI_SUCCESS,
OCI_INVALID_HANDLE,
OCI_ERROR.
Gets the length of a file.
sword OCIFileGetLength( dvoid *hndl, OCIError *err, OraText *filename, OraText *path, ubig_ora *lenp);
The OCI environment or user session handle.
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().
The file name as a null-terminated string.
The path of the file as a null-terminated string.
Set to the length of the file in bytes.
OCI_SUCCESS,
OCI_INVALID_HANDLE,
OCI_ERROR.
Writes buffered data to a file.
sword OCIFileFlush( dvoid *h OCIError *err, OCIFileObject *filep);
The OCI environment or user session handle.
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().
A file identifier that uniquely references the file.
OCI_SUCCESS,
OCI_INVALID_HANDLE,
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 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". */
|
![]() Copyright © 1996-2000, Oracle Corporation. All Rights Reserved. |
|