Oracle® Call Interface Programmer's Guide 11g Release 2 (11.2) Part Number E10646-08 |
|
|
PDF · Mobi · ePub |
Table 20-5 lists the file I/O interface functions that are described in this section.
Table 20-5 File I/O Interface Functions
Function | Purpose |
---|---|
Close a previously opened file |
|
Test to see if the file exists |
|
Write buffered data to a file |
|
Get the length of a file |
|
Initialize the OCIFile package |
|
Open a file |
|
Read from a file into a buffer |
|
Change the current position in a file |
|
Terminate the OCIFile package |
|
Write |
See Also:
Oracle Database Data Cartridge Developer's Guide for more information about using these functionsThe OCIFileObject
data structure holds information about the way in which a file should be opened and the way in which it is accessed after 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().
Closes a previously opened file.
sword OCIFileClose( void *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 function returns OCI_SUCCESS, the OCIFileObject
structure pointed to by filep
is destroyed. Therefore, you should not attempt to access this structure after this function returns OCI_SUCCESS.
OCI_SUCCESS
; OCI_INVALID_HANDLE
; or OCI_ERROR
.
Tests to see if the file exists.
sword OCIFileExists( void *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
; or OCI_ERROR
.
Writes buffered data to a file.
sword OCIFileFlush( void *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 file identifier that uniquely references the file.
OCI_SUCCESS
; OCI_INVALID_HANDLE
; or OCI_ERROR
.
Gets the length of a file.
sword OCIFileGetLength( void *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
; or OCI_ERROR
.
Initializes the OCIFile package. It must be called before any other OCIFile routine is called.
sword OCIFileInit( void *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
; or OCI_ERROR
.
Opens a file.
sword OCIFileOpen( void *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 is to be created if it does not exist. Valid values are:
OCI_FILE_TRUNCATE
— Create a file regardless of whether it exists. If the file exists, overwrite the existing file.
OCI_FILE_EXCL
— Fail if the file exists; otherwise, create a file.
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 used with the logical operator OR 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
; or OCI_ERROR
.
Reads from a file into a buffer.
sword OCIFileRead( void *hndl, OCIError *err, OCIFileObject *filep, void *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 is 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 are read into the user buffer. The read ends either when the user buffer is full, or when it reaches end-of-file.
OCI_SUCCESS
; OCI_INVALID_HANDLE
; or OCI_ERROR
.
Changes the current position in a file.
sword OCIFileSeek( void *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 from which to seek. Use one of the following values:
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 where reading begins.
The direction to go from the origin.
Note:
The direction can be eitherOCIFILE_FORWARD
or OCIFILE_BACKWARD
.This function allows a seek past the end of the file. Reading from such a position causes an end-of-file condition to be reported. Writing to such a position does 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
.
Terminates the OCIFile package. It must be called after the OCIFile package is no longer being used.
sword OCIFileTerm( void *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
; or OCI_ERROR
.
Writes buflen
bytes into the file.
sword OCIFileWrite( void *hndl, OCIError *err, OCIFileObject *filep, void *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 which the data is 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
; or OCI_ERROR
.