OCILIB (C and C++ Driver for Oracle)  4.7.5
Open source and cross platform Oracle Driver delivering efficient access to Oracle databases.
Loading...
Searching...
No Matches
Formatted functions

Detailed Description

OcilibCApiMetadata

OCILIB offers some smart routines that takes a variable number of arguments in order to minimize OCILIB function calls and reduce the amount of code lines

On Windows platforms, the target programming language must support the __cdecl calling convention

Note
OCI_Immediate() and OCI_ImmediateFmt() support all OCILIB supported types for output result, except :
  • OCI_Long
  • OCI_Statement If a query output result contains one of these unsupported types, the function returns FALSE
In the parameter list, every output placeholder MUST be preceded by an integer parameter that indicates the type of the placeholder in order to handle correctly the given pointer.

Possible values for indicating placeholders type :

Note
For output strings and Raws, returned data is copied to the given buffer instead of returning a pointer the real data. So these buffers must be big enough to hold the column content. No size check is performed.
Warning
Input parameters for formatted function only support a restricted set of data types !

Supported input identifiers :

Example
#include "ocilib.h"
/* requires script demo/products.sql */
void err_handler(OCI_Error *err)
{
printf("%s\n", OCI_ErrorGetString(err));
}
int main(void)
{
int code;
char name[50];
if (!OCI_Initialize(err_handler, NULL, OCI_ENV_DEFAULT))
{
return EXIT_FAILURE;
}
cn = OCI_ConnectionCreate("db", "usr", "pwd", OCI_SESSION_DEFAULT);
/* sql format with params ----------------------------------------------- */
code = 1;
OCI_ExecuteStmtFmt(st, "select name from products where code = %i", code);
rs = OCI_GetResultset(st);
while (OCI_FetchNext(rs))
{
printf("article : %s\n", OCI_GetString(rs, 1));
}
/* sql immediate (parse, exec, one fetch) ------------------------------- */
OCI_Immediate(cn, "select name from products where code = 2", OCI_ARG_TEXT, name);
printf("article : %s\n", name);
/* sql immediate (parse, exec, one fetch) with params ------------------- */
code = 1;
OCI_ImmediateFmt(cn, "select name from products where code = %i", code, OCI_ARG_TEXT, name);
printf("article : %s\n", name);
return EXIT_SUCCESS;
}
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:390
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 error message from error handle.
OCI_SYM_PUBLIC boolean OCI_API OCI_FetchNext(OCI_Resultset *rs)
Fetch the next row of the resultset.
OCI_SYM_PUBLIC const otext *OCI_API OCI_GetString(OCI_Resultset *rs, unsigned int index)
Return the current string value of the column at the given index in the resultset.
OCI_SYM_PUBLIC OCI_Resultset *OCI_API OCI_GetResultset(OCI_Statement *stmt)
Retrieve the resultset handle from an executed statement.
OCI_SYM_PUBLIC boolean OCI_Immediate(OCI_Connection *con, const otext *sql,...)
Perform 3 calls (prepare+execute+fetch) in 1 call.
OCI_SYM_PUBLIC boolean OCI_ExecuteStmtFmt(OCI_Statement *stmt, const otext *sql,...)
Execute a formatted SQL statement or PL/SQL block.
OCI_SYM_PUBLIC boolean OCI_ImmediateFmt(OCI_Connection *con, const otext *sql,...)
Performs 4 call (prepare+bind+execute+fetch) in 1 call.
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 OCI_Statement *OCI_API OCI_StatementCreate(OCI_Connection *con)
Create a statement object and return its handle.
OCI_SYM_PUBLIC boolean OCI_API OCI_StatementFree(OCI_Statement *stmt)
Free a statement and all resources associated to it (resultsets ...)

Functions

OCI_SYM_PUBLIC boolean OCI_Immediate (OCI_Connection *con, const otext *sql,...)
 Perform 3 calls (prepare+execute+fetch) in 1 call.
 
OCI_SYM_PUBLIC boolean OCI_ImmediateFmt (OCI_Connection *con, const otext *sql,...)
 Performs 4 call (prepare+bind+execute+fetch) in 1 call.
 
OCI_SYM_PUBLIC boolean OCI_PrepareFmt (OCI_Statement *stmt, const otext *sql,...)
 Prepare a formatted SQL statement or PL/SQL block.
 
OCI_SYM_PUBLIC boolean OCI_ExecuteStmtFmt (OCI_Statement *stmt, const otext *sql,...)
 Execute a formatted SQL statement or PL/SQL block.
 
OCI_SYM_PUBLIC boolean OCI_ParseFmt (OCI_Statement *stmt, const otext *sql,...)
 Parse a formatted SQL statement or PL/SQL block.
 
OCI_SYM_PUBLIC boolean OCI_DescribeFmt (OCI_Statement *stmt, const otext *sql,...)
 Describe the select list of a formatted SQL select statement.
 

Function Documentation

◆ OCI_Immediate()

OCI_SYM_PUBLIC boolean OCI_Immediate ( OCI_Connection con,
const otext *  sql,
  ... 
)

#include <api.h>

Perform 3 calls (prepare+execute+fetch) in 1 call.

Parameters
con- Connection handle
sql- SQL statement
...- List of program variables address to store the result of fetch operation
Note
Every output parameter MUST be preceded by an integer parameter that indicates the type of the placeholder in order to handle correctly the given pointer.

TRUE on success otherwise FALSE

◆ OCI_ImmediateFmt()

OCI_SYM_PUBLIC boolean OCI_ImmediateFmt ( OCI_Connection con,
const otext *  sql,
  ... 
)

#include <api.h>

Performs 4 call (prepare+bind+execute+fetch) in 1 call.

Parameters
con- Connection handle
sql- SQL statement
...- List of program values to format the SQL followed by the output variables addresses for the fetch operation

TRUE on success otherwise FALSE

◆ OCI_PrepareFmt()

OCI_SYM_PUBLIC boolean OCI_PrepareFmt ( OCI_Statement stmt,
const otext *  sql,
  ... 
)

#include <api.h>

Prepare a formatted SQL statement or PL/SQL block.

Parameters
stmt- Statement handle
sql- SQL statement
...- List of program values to format the SQL
Returns
TRUE on success otherwise FALSE

◆ OCI_ExecuteStmtFmt()

OCI_SYM_PUBLIC boolean OCI_ExecuteStmtFmt ( OCI_Statement stmt,
const otext *  sql,
  ... 
)

#include <api.h>

Execute a formatted SQL statement or PL/SQL block.

Parameters
stmt- Statement handle
sql- SQL statement
...- List of program values to format the SQL
Returns
TRUE on success otherwise FALSE
Warning
If a SQL warning occurs:
  • the function returns TRUE
  • the SQL warning triggers the global error handler with an OCI_Error having its OCI_ErrorGetType() attribute set to OCI_ERR_WARNING
  • If OCILIB is initialized with the OCI_ENV_CONTEXT mode, OCI_GetLastError() will return the OCI_Error object corresponding to the warning

◆ OCI_ParseFmt()

OCI_SYM_PUBLIC boolean OCI_ParseFmt ( OCI_Statement stmt,
const otext *  sql,
  ... 
)

#include <api.h>

Parse a formatted SQL statement or PL/SQL block.

Parameters
stmt- Statement handle
sql- SQL statement
...- List of program values to format the SQL
Note
This call sends the SQL or PL/SQL command to the server for parsing only. The command is not executed. This call is only useful to check is a command is valid or not.
This call prepares the statement (internal call to OCI_Prepare()) and ask the Oracle server to parse its SQL or PL/SQL command. OCI_Execute() can be call after OCI_ParseFmt() in order to execute the statement, which means that the server will re-parse again the command.
Warning
Do not use OCI_ParseFmt() unless you're only interested in the parsing result because the statement will be parsed again when executed and thus leading to unnecessary server round-trips and less performance
Returns
TRUE on success otherwise FALSE

◆ OCI_DescribeFmt()

OCI_SYM_PUBLIC boolean OCI_DescribeFmt ( OCI_Statement stmt,
const otext *  sql,
  ... 
)

#include <api.h>

Describe the select list of a formatted SQL select statement.

Parameters
stmt- Statement handle
sql- SQL statement
...- List of program values to format the SQL
Note
This call sends the SELECT SQL order to the server for retrieving the description of the select order only. The command is not executed. This call is only useful to retrieve information on the associated resultset Call OCI_GetResultset() after OCI_Describe() to access to SELECT list information
This call prepares the statement (internal call to OCI_Prepare()) and ask the Oracle server to describe the output SELECT list. OCI_Execute() can be call after OCI_Describe() in order to execute the statement, which means that the server will parse, and describe again the SQL order.
Warning
Do not use OCI_Describe() unless you're only interested in the resultset information because the statement will be parsed again when executed and thus leading to unnecessary server round-trips and less performance
Returns
TRUE on success otherwise FALSE