Functions

Formatted functions


Detailed Description

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 datatypes !

Supported input identifiers :

Example
#include "ocilib.h"

int main(void)
{
    OCI_Connection *cn;
    OCI_Statement  *st;
    OCI_Resultset  *rs;
 
    int code = 1;
    char name[50];
  
    if (!OCI_Initialize(NULL, NULL, OCI_ENV_DEFAULT))
        return EXIT_FAILURE;

    cn = OCI_ConnectionCreate("db", "usr", "pwd", OCI_SESSION_DEFAULT);
    st = OCI_StatementCreate(cn);
 
    /* sql format with params ----------------------------------------------- */

    OCI_ExecuteStmtFmt(st, "select article from test_fetch 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 code, article from test_fetch where code = 1", 
                  OCI_ARG_INT, &code, OCI_ARG_TEXT, name);

    printf("article : %s - code %i\n", name, code);

    /* sql immediate (parse, exec, one fetch) with params ------------------- */

    
    OCI_ImmediateFmt(cn, "select article from test_fetch where code = %i", 
                          code, OCI_ARG_TEXT, name);

    printf("article : %s\n", name);

    OCI_Cleanup();
 
    return EXIT_SUCCESS;
}

Functions

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

Function Documentation

OCI_EXPORT boolean OCI_Immediate ( OCI_Connection con,
const mtext *  sql,
  ... 
)

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

Definition at line 2109 of file statement.c.

References OCI_ExecuteStmt(), OCI_GetStatementType(), OCI_StatementCreate(), and OCI_StatementFree().

OCI_EXPORT boolean OCI_ImmediateFmt ( OCI_Connection con,
const mtext *  sql,
  ... 
)

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

Definition at line 2155 of file statement.c.

References OCI_GetStatementType(), OCI_Prepare(), OCI_StatementCreate(), and OCI_StatementFree().

OCI_EXPORT boolean OCI_PrepareFmt ( OCI_Statement stmt,
const mtext *  sql,
  ... 
)

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

Definition at line 1933 of file statement.c.

References OCI_Prepare().

OCI_EXPORT boolean OCI_ExecuteStmtFmt ( OCI_Statement stmt,
const mtext *  sql,
  ... 
)

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

Definition at line 1991 of file statement.c.

References OCI_Prepare().

OCI_EXPORT boolean OCI_ParseFmt ( OCI_Statement stmt,
const mtext *  sql,
  ... 
)

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 reparse 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 roundtrips and less performance
Returns:
TRUE on success otherwise FALSE

Definition at line 2050 of file statement.c.

References OCI_Prepare().