OCILIB (C and C++ Driver for Oracle)  4.9.0
Open source and cross platform Oracle Driver delivering efficient access to Oracle databases.
Loading...
Searching...
No Matches
Long objects

Detailed Description

OcilibCApiFiles

Long Objects encapsulate Oracle LONG data types and were used to store large buffers in Oracle databases.

They are still supported but are deprecated. Oracle now provides a newer and better way to deal with data that needs large storage: LOBs.

OCILIB supports this data type because it was and still is widely used.

OCILIB provides a set of APIs for manipulating LONGs that is very close to the one provided for LOBs.

OCILIB currently supports 2 types of Long Objects:

OCI_Long objects can be:

Example
#include "ocilib.h"
/* requires script demo/long.sql */
#define FILENAME "data.lst"
#define SIZE_BUF 512
#define SIZE_LST 2345
void err_handler(OCI_Error *err)
{
printf("%s\n", OCI_ErrorGetString(err));
}
int main(void)
{
OCI_Long *lg;
FILE *f;
char buffer[SIZE_BUF];
int i, n;
if (!OCI_Initialize(err_handler, NULL, OCI_ENV_DEFAULT))
{
return EXIT_FAILURE;
}
cn = OCI_ConnectionCreate("db", "usr", "pwd", OCI_SESSION_DEFAULT);
/* create the data file */
f = fopen(FILENAME, "wb");
if (f)
{
for (i = 1, n = SIZE_LST; i <= n; i++)
{
fputc('A' + (i % CHAR_MAX), f);
}
fclose(f);
}
/* open the data file */
f = fopen(FILENAME, "rb");
if (f)
{
fseek(f, 0, SEEK_END);
n = ftell(f);
rewind(f);
printf("\n%d bytes to write\n", n);
lg = OCI_LongCreate(st, OCI_BLONG);
OCI_Prepare(st, "insert into test_long_raw(code, content) values (1, :data)");
OCI_BindLong(st, ":data", lg, n);
/* write data into table by chunks of SIZE_BUF bytes */
while ((n = (int) fread(buffer, 1, sizeof(buffer), f)))
{
OCI_LongWrite(lg, buffer, n);
}
printf("\n%d bytes written\n", OCI_LongGetSize(lg));
fclose(f);
}
/* FETCHING LONGS -------------------------------------------- */
OCI_ExecuteStmt(st, "select content from test_long_raw where code = 1");
OCI_SetPieceSize(st, 10000);
rs = OCI_GetResultset(st);
/* read data by chunks of 2048 bytes*/
while (OCI_FetchNext(rs))
{
lg = OCI_GetLong(rs, 1);
while ((n = OCI_LongRead(lg, buffer, sizeof(buffer)))) {}
printf("\n%d bytes read\n", OCI_LongGetSize(lg));
}
return EXIT_SUCCESS;
}
OCI_SYM_PUBLIC boolean OCI_API OCI_BindLong(OCI_Statement *stmt, const otext *name, OCI_Long *data, unsigned int size)
Bind a Long variable.
OCI_SYM_PUBLIC boolean OCI_API OCI_ConnectionFree(OCI_Connection *con)
Close a physical connection to an Oracle database server.
OCI_SYM_PUBLIC OCI_Connection *OCI_API OCI_ConnectionCreate(const otext *db, const otext *user, const otext *pwd, unsigned int mode)
Create a physical connection to an Oracle database server.
struct OCI_Connection OCI_Connection
Oracle physical connection.
Definition: types.h:124
struct OCI_Statement OCI_Statement
Oracle SQL or PL/SQL statement.
Definition: types.h:136
struct OCI_Error OCI_Error
Encapsulates an Oracle or OCILIB exception.
Definition: types.h:410
struct OCI_Long OCI_Long
Oracle Long data type.
Definition: types.h:260
struct OCI_Resultset OCI_Resultset
Collection of output columns from a select statement.
Definition: types.h:163
OCI_SYM_PUBLIC const otext *OCI_API OCI_ErrorGetString(OCI_Error *err)
Retrieve the error message string from an error handle.
OCI_SYM_PUBLIC boolean OCI_API OCI_FetchNext(OCI_Resultset *rs)
Fetch the next row of the result set.
OCI_SYM_PUBLIC OCI_Long *OCI_API OCI_GetLong(OCI_Resultset *rs, unsigned int index)
Return the current Long value of the column at the given index in the result set.
OCI_SYM_PUBLIC OCI_Resultset *OCI_API OCI_GetResultset(OCI_Statement *stmt)
Retrieve the result set handle from an executed statement.
OCI_SYM_PUBLIC boolean OCI_API OCI_Cleanup(void)
Clean up all resources allocated by the library.
OCI_SYM_PUBLIC boolean OCI_API OCI_Initialize(POCI_ERROR err_handler, const otext *lib_path, unsigned int mode)
Initialize the library.
OCI_SYM_PUBLIC boolean OCI_API OCI_LongFree(OCI_Long *lg)
Free a local temporary long.
OCI_SYM_PUBLIC unsigned int OCI_API OCI_LongGetSize(OCI_Long *lg)
Return the buffer size of a Long object in bytes (OCI_BLONG) or characters (OCI_CLONG)
OCI_SYM_PUBLIC unsigned int OCI_API OCI_LongRead(OCI_Long *lg, void *buffer, unsigned int len)
Read a portion of a long into the given buffer [Obsolete].
OCI_SYM_PUBLIC unsigned int OCI_API OCI_LongWrite(OCI_Long *lg, void *buffer, unsigned int len)
Write a buffer into a Long.
OCI_SYM_PUBLIC OCI_Long *OCI_API OCI_LongCreate(OCI_Statement *stmt, unsigned int type)
Create a local temporary Long instance.
OCI_SYM_PUBLIC boolean OCI_API OCI_SetPieceSize(OCI_Statement *stmt, unsigned int size)
Set the piece size for dynamic fetch operations (XMLTYPE, LONGs)
OCI_SYM_PUBLIC OCI_Statement *OCI_API OCI_StatementCreate(OCI_Connection *con)
Create a statement object and return its handle.
OCI_SYM_PUBLIC boolean OCI_API OCI_ExecuteStmt(OCI_Statement *stmt, const otext *sql)
Prepare and execute a SQL statement or PL/SQL block in a single call.
OCI_SYM_PUBLIC boolean OCI_API OCI_StatementFree(OCI_Statement *stmt)
Free a statement and all resources associated with it (result sets, bind variables,...
OCI_SYM_PUBLIC boolean OCI_API OCI_Prepare(OCI_Statement *stmt, const otext *sql)
Prepare a SQL statement or PL/SQL block.
OCI_SYM_PUBLIC boolean OCI_API OCI_Execute(OCI_Statement *stmt)
Execute a prepared SQL statement or PL/SQL block.
OCI_SYM_PUBLIC boolean OCI_API OCI_Commit(OCI_Connection *con)
Commit current pending changes.

Functions

OCI_SYM_PUBLIC OCI_Long *OCI_API OCI_LongCreate (OCI_Statement *stmt, unsigned int type)
 Create a local temporary Long instance.
 
OCI_SYM_PUBLIC boolean OCI_API OCI_LongFree (OCI_Long *lg)
 Free a local temporary long.
 
OCI_SYM_PUBLIC unsigned int OCI_API OCI_LongGetType (OCI_Long *lg)
 Return the type of the given Long object.
 
OCI_SYM_PUBLIC unsigned int OCI_API OCI_LongRead (OCI_Long *lg, void *buffer, unsigned int len)
 Read a portion of a long into the given buffer [Obsolete].
 
OCI_SYM_PUBLIC unsigned int OCI_API OCI_LongWrite (OCI_Long *lg, void *buffer, unsigned int len)
 Write a buffer into a Long.
 
OCI_SYM_PUBLIC unsigned int OCI_API OCI_LongGetSize (OCI_Long *lg)
 Return the buffer size of a Long object in bytes (OCI_BLONG) or characters (OCI_CLONG)
 
OCI_SYM_PUBLIC void *OCI_API OCI_LongGetBuffer (OCI_Long *lg)
 Return the internal buffer of an OCI_Long object read from a fetch sequence.
 

Function Documentation

◆ OCI_LongCreate()

OCI_SYM_PUBLIC OCI_Long *OCI_API OCI_LongCreate ( OCI_Statement stmt,
unsigned int  type 
)

#include <api.h>

Create a local temporary Long instance.

Parameters
stmt- Statement handle
type- Long type

Supported Long types:

  • OCI_BLONG : Binary Long.
  • OCI_CLONG : Character Long.
Returns
The Long handle on success, or NULL on failure.

Referenced by ocilib::Long< T, U >::Long().

◆ OCI_LongFree()

OCI_SYM_PUBLIC boolean OCI_API OCI_LongFree ( OCI_Long lg)

#include <api.h>

Free a local temporary long.

Parameters
lg- Long handle
Warning
Only Longs created with OCI_LongCreate() should be freed by OCI_LongFree().
Returns
TRUE on success, otherwise FALSE.

◆ OCI_LongGetType()

OCI_SYM_PUBLIC unsigned int OCI_API OCI_LongGetType ( OCI_Long lg)

#include <api.h>

Return the type of the given Long object.

Parameters
lg- Long handle
Note
For possible values, see OCI_LongCreate().
Returns
The Long type, or OCI_UNKNOWN if the input handle is NULL.

◆ OCI_LongRead()

OCI_SYM_PUBLIC unsigned int OCI_API OCI_LongRead ( OCI_Long lg,
void *  buffer,
unsigned int  len 
)

#include <api.h>

Read a portion of a long into the given buffer [Obsolete].

Parameters
lg- Long handle
buffer- Pointer to a buffer
len- Length of the buffer in bytes / characters
Note
  • From version 2.0.0, this function is obsolete because OCILIB now fetches all data during the OCIFetchNext() call.
  • This call now reads the internal OCI_Long object allocated buffer.
  • The internal buffer can be directly accessed with OCI_LongGetBuffer().
  • For OCI_CLONG, parameter 'len' and returned value are expressed in characters.
  • For OCI_BLONG, parameter 'len' and returned value are expressed in bytes.
Returns
  • Number of bytes/characters read on success.
  • 0 if there is nothing more to read.
  • 0 on failure.

◆ OCI_LongWrite()

OCI_SYM_PUBLIC unsigned int OCI_API OCI_LongWrite ( OCI_Long lg,
void *  buffer,
unsigned int  len 
)

#include <api.h>

Write a buffer into a Long.

Parameters
lg- Long handle
buffer- Pointer to a buffer
len- Length of the buffer in bytes (OCI_BLONG) or characters (OCI_CLONG)
Returns
The number of bytes (OCI_BLONG) or characters (OCI_CLONG) written on success, or 0 on failure.

Referenced by ocilib::Long< T, U >::Write().

◆ OCI_LongGetSize()

OCI_SYM_PUBLIC unsigned int OCI_API OCI_LongGetSize ( OCI_Long lg)

#include <api.h>

Return the buffer size of a Long object in bytes (OCI_BLONG) or characters (OCI_CLONG)

Parameters
lg- Long handle
Returns
The buffer size, or 0 on failure.

Referenced by ocilib::Long< T, U >::GetLength().

◆ OCI_LongGetBuffer()

OCI_SYM_PUBLIC void *OCI_API OCI_LongGetBuffer ( OCI_Long lg)

#include <api.h>

Return the internal buffer of an OCI_Long object read from a fetch sequence.

Parameters
lg- Long handle
Returns
The internal buffer pointer, or NULL on failure.