Oracle OCI supplies a set APIs to manipulate this datatype.
OCILIB encapsulates this API by supplying:
OCIB currently supports 2 types of Lobs :
#include "ocilib.h" int main(void) { OCI_Connection *cn; OCI_Statement *st; OCI_Resultset *rs; OCI_File *file; char buffer[256]; int n; if (!OCI_Initialize(NULL, NULL, OCI_ENV_DEFAULT)) return EXIT_FAILURE; cn = OCI_ConnectionCreate("db", "usr", "pwd", OCI_SESSION_DEFAULT); st = OCI_StatementCreate(cn); file = OCI_FileCreate(cn, OCI_CFILE); OCI_FileSetName(file, "MYDIR", "MyfileName"); /* check if faile exists */ if (OCI_FileExists(file)) { printf("file size : %d\n", OCI_FileGetSize(file)); printf("file dir : %s\n", OCI_FileGetDirectory(file)); printf("file name : %s\n", OCI_FileGetName(file)); } /* bind for inserting into table */ OCI_Prepare(st, "insert into my_bfile_table(code, value) values (1, :bfile)"); OCI_BindFile(st, ":bfile", file); OCI_Execute(st); OCI_Commit(cn); /* free local file object */ OCI_FileFree(file), /* fetch bfile data from table */ OCI_ExecuteStmt(st, "select code, value from my_bfile_table"); rs = OCI_GetResultset(st); while (OCI_FetchNext(rs)) { file = OCI_GetFile(rs, 2); OCI_FileOpen(file); printf("file size %d\n", OCI_FileGetSize(file)); printf("file dir %s\n", OCI_FileGetDirectory(file)); printf("file name %s\n", OCI_FileGetName(file)); while (n = OCI_FileRead(file, buffer, sizeof(buffer)-1)) { buffer[n] = 0; printf(buffer); } OCI_FileClose(file); } OCI_Cleanup(); return EXIT_SUCCESS; }
Functions | |
OCI_EXPORT OCI_File *OCI_API | OCI_FileCreate (OCI_Connection *con, unsigned int type) |
Create a file object instance. | |
OCI_EXPORT boolean OCI_API | OCI_FileFree (OCI_File *file) |
Free a local File object. | |
OCI_EXPORT unsigned int OCI_API | OCI_FileGetType (OCI_File *file) |
Return the type of the given File object. | |
OCI_EXPORT boolean OCI_API | OCI_FileSeek (OCI_File *file, big_uint offset, unsigned int mode) |
Perform a seek operation on the OCI_File content buffer. | |
OCI_EXPORT big_uint OCI_API | OCI_FileGetOffset (OCI_File *file) |
Return the current position in the file. | |
OCI_EXPORT unsigned int OCI_API | OCI_FileRead (OCI_File *file, void *buffer, unsigned int len) |
Read a portion of a file into the given buffer. | |
OCI_EXPORT big_uint OCI_API | OCI_FileGetSize (OCI_File *file) |
Return the size in bytes of a file. | |
OCI_EXPORT boolean OCI_API | OCI_FileExists (OCI_File *file) |
Check if the given file exists on server. | |
OCI_EXPORT boolean OCI_API | OCI_FileSetName (OCI_File *file, const mtext *dir, const mtext *name) |
Set the directory and file name of FILE handle. | |
OCI_EXPORT const mtext *OCI_API | OCI_FileGetDirectory (OCI_File *file) |
Return the directory of the given file. | |
OCI_EXPORT const mtext *OCI_API | OCI_FileGetName (OCI_File *file) |
Return the name of the given file. | |
OCI_EXPORT boolean OCI_API | OCI_FileOpen (OCI_File *file) |
Open a file for reading. | |
OCI_EXPORT boolean OCI_API | OCI_FileIsOpen (OCI_File *file) |
Check if the specified file is opened within the file handle. | |
OCI_EXPORT boolean OCI_API | OCI_FileClose (OCI_File *file) |
Close a file. | |
OCI_EXPORT boolean OCI_API | OCI_FileIsEqual (OCI_File *file, OCI_File *file2) |
Compare two file handle for equality. | |
OCI_EXPORT boolean OCI_API | OCI_FileAssign (OCI_File *file, OCI_File *file_src) |
Assign a file to another one. |
Assign a file to another one.
file | - Destination File handle | |
file_src | - Source File handle |
Definition at line 593 of file file.c.
References OCI_File::con, OCI_Connection::cxt, OCI_Connection::err, OCI_File::handle, and OCI_File::hstate.
Referenced by OCI_ElemSetFile(), and OCI_ObjectSetFile().
OCI_EXPORT boolean OCI_API OCI_FileClose | ( | OCI_File * | file | ) |
Close a file.
file | - File handle |
Definition at line 544 of file file.c.
References OCI_File::con, OCI_Connection::cxt, OCI_Connection::err, OCI_File::handle, and OCI_Connection::nb_files.
OCI_EXPORT OCI_File* OCI_API OCI_FileCreate | ( | OCI_Connection * | con, | |
unsigned int | type | |||
) |
OCI_EXPORT boolean OCI_API OCI_FileExists | ( | OCI_File * | file | ) |
Check if the given file exists on server.
file | - File handle |
Definition at line 398 of file file.c.
References OCI_File::con, OCI_Connection::cxt, OCI_Connection::err, and OCI_File::handle.
OCI_EXPORT boolean OCI_API OCI_FileFree | ( | OCI_File * | file | ) |
Free a local File object.
file | - File handle |
Definition at line 209 of file file.c.
References OCI_File::dir, OCI_File::handle, OCI_File::hstate, and OCI_File::name.
Referenced by OCI_ElemFree().
OCI_EXPORT const mtext* OCI_API OCI_FileGetDirectory | ( | OCI_File * | file | ) |
Return the directory of the given file.
file | - File handle |
Definition at line 460 of file file.c.
References OCI_File::dir.
OCI_EXPORT const mtext* OCI_API OCI_FileGetName | ( | OCI_File * | file | ) |
Return the name of the given file.
file | - File handle |
Definition at line 477 of file file.c.
References OCI_File::name.
OCI_EXPORT big_uint OCI_API OCI_FileGetOffset | ( | OCI_File * | file | ) |
Return the current position in the file.
file | - File handle |
Definition at line 264 of file file.c.
References OCI_File::offset.
OCI_EXPORT big_uint OCI_API OCI_FileGetSize | ( | OCI_File * | file | ) |
Return the size in bytes of a file.
file | - File handle |
Definition at line 351 of file file.c.
References OCI_File::con, OCI_Connection::cxt, OCI_Connection::err, and OCI_File::handle.
Referenced by OCI_FileSeek().
OCI_EXPORT unsigned int OCI_API OCI_FileGetType | ( | OCI_File * | file | ) |
Return the type of the given File object.
file | - File handle |
Definition at line 338 of file file.c.
References OCI_File::type.
Compare two file handle for equality.
file | - File handle | |
file2 | - File2 handle |
Definition at line 569 of file file.c.
References OCI_File::con, and OCI_File::handle.
OCI_EXPORT boolean OCI_API OCI_FileIsOpen | ( | OCI_File * | file | ) |
Check if the specified file is opened within the file handle.
file | - File handle |
Definition at line 521 of file file.c.
References OCI_File::con, OCI_Connection::cxt, OCI_Connection::err, and OCI_File::handle.
OCI_EXPORT boolean OCI_API OCI_FileOpen | ( | OCI_File * | file | ) |
Open a file for reading.
file | - File handle |
Definition at line 495 of file file.c.
References OCI_File::con, OCI_Connection::cxt, OCI_Connection::err, OCI_File::handle, and OCI_Connection::nb_files.
OCI_EXPORT unsigned int OCI_API OCI_FileRead | ( | OCI_File * | file, | |
void * | buffer, | |||
unsigned int | len | |||
) |
Read a portion of a file into the given buffer.
file | - File handle | |
buffer | - Pointer to a buffer | |
len | - Length of the buffer in bytes |
Definition at line 277 of file file.c.
References OCI_File::con, OCI_Connection::cxt, OCI_Connection::err, OCI_File::handle, and OCI_File::offset.
Referenced by OCI_GetString().
OCI_EXPORT boolean OCI_API OCI_FileSeek | ( | OCI_File * | file, | |
big_uint | offset, | |||
unsigned int | mode | |||
) |
Perform a seek operation on the OCI_File content buffer.
file | - File handle | |
offset | - Offset from current position | |
mode | - Seek mode |
Definition at line 235 of file file.c.
References OCI_FileGetSize(), and OCI_File::offset.
Referenced by OCI_GetString().
OCI_EXPORT boolean OCI_API OCI_FileSetName | ( | OCI_File * | file, | |
const mtext * | dir, | |||
const mtext * | name | |||
) |
Set the directory and file name of FILE handle.
file | - File handle | |
dir | - File directory | |
name | - File name |
Definition at line 421 of file file.c.
References OCI_File::con, OCI_Connection::err, and OCI_File::handle.