OCILIB (C Driver for Oracle) 3.9.2
|
Executing SQL statements or PL/SQL blocks is really simple with OCILIB.
First, call OCI_StatementCreate() to allocate a statement handle. Then :
These two steps can be done together by calling OCI_ExecuteStmt() that prepares and executes in one go.
To find out if the statement has affected any rows, call OCI_GetAffectedRows()
Finally, release the statement and its resources with OCI_StatementFree()
#include "ocilib.h" int main(void) { OCI_Connection *cn; OCI_Statement *st; if (!OCI_Initialize(NULL, NULL, OCI_ENV_DEFAULT)) return EXIT_FAILURE; cn = OCI_ConnectionCreate("db", "usr", "pwd", OCI_SESSION_DEFAULT); st = OCI_StatementCreate(cn); /* prepare and execute in 2 steps */ OCI_Prepare(st, "delete from test_fetch where code > 10"); OCI_Execute(st); /* prepare/execute in 1 step */ OCI_ExecuteStmt(st, "delete from test_fetch where code > 1"); printf("%d row deleted", OCI_GetAffectedRows(st)); OCI_Commit(cn); OCI_Cleanup(); return EXIT_SUCCESS; }
Functions | |
OCI_EXPORT OCI_Statement *OCI_API | OCI_StatementCreate (OCI_Connection *con) |
Create a statement object and return its handle. | |
OCI_EXPORT boolean OCI_API | OCI_StatementFree (OCI_Statement *stmt) |
Free a statement and all resources associated to it (resultsets ...) | |
OCI_EXPORT boolean OCI_API | OCI_Prepare (OCI_Statement *stmt, const mtext *sql) |
Prepare a SQL statement or PL/SQL block. | |
OCI_EXPORT boolean OCI_API | OCI_Execute (OCI_Statement *stmt) |
Execute a prepared SQL statement or PL/SQL block. | |
OCI_EXPORT boolean OCI_API | OCI_ExecuteStmt (OCI_Statement *stmt, const mtext *sql) |
Execute a SQL statement or PL/SQL block. | |
OCI_EXPORT boolean OCI_API | OCI_Parse (OCI_Statement *stmt, const mtext *sql) |
Parse a SQL statement or PL/SQL block. | |
OCI_EXPORT boolean OCI_API | OCI_Describe (OCI_Statement *stmt, const mtext *sql) |
Describe the select list of a SQL select statement. | |
OCI_EXPORT const mtext *OCI_API | OCI_GetSql (OCI_Statement *stmt) |
Return the last SQL or PL/SQL statement prepared or executed by the statement. | |
OCI_EXPORT unsigned int OCI_API | OCI_GetSqlErrorPos (OCI_Statement *stmt) |
Return the error position (in terms of characters) in the SQL statement where the error occurred in case of SQL parsing error. | |
OCI_EXPORT unsigned int OCI_API | OCI_GetAffectedRows (OCI_Statement *stmt) |
Return the number of rows affected by the SQL statement. | |
OCI_EXPORT unsigned int OCI_API | OCI_GetSQLCommand (OCI_Statement *stmt) |
Return the Oracle SQL code the command held by the statement handle. | |
OCI_EXPORT const mtext *OCI_API | OCI_GetSQLVerb (OCI_Statement *stmt) |
Return the verb of the SQL command held by the statement handle. |
OCI_EXPORT OCI_Statement* OCI_API OCI_StatementCreate | ( | OCI_Connection * | con | ) |
Create a statement object and return its handle.
con | - Connection handle |
Definition at line 1863 of file statement.c.
Referenced by OCI_DatabaseShutdown(), OCI_DatabaseStartup(), OCI_Immediate(), OCI_ImmediateFmt(), OCI_QueueAlter(), OCI_QueueCreate(), OCI_QueueDrop(), OCI_QueueStart(), OCI_QueueStop(), OCI_QueueTableAlter(), OCI_QueueTableCreate(), OCI_QueueTableDrop(), OCI_QueueTableMigrate(), OCI_QueueTablePurge(), and OCI_ServerEnableOutput().
OCI_EXPORT boolean OCI_API OCI_StatementFree | ( | OCI_Statement * | stmt | ) |
Free a statement and all resources associated to it (resultsets ...)
stmt | - Connection handle |
Definition at line 1891 of file statement.c.
Referenced by OCI_DatabaseShutdown(), OCI_DatabaseStartup(), OCI_Immediate(), OCI_ImmediateFmt(), OCI_QueueAlter(), OCI_QueueCreate(), OCI_QueueDrop(), OCI_QueueStart(), OCI_QueueStop(), OCI_QueueTableAlter(), OCI_QueueTableCreate(), OCI_QueueTableDrop(), OCI_QueueTableMigrate(), OCI_QueueTablePurge(), and OCI_ServerDisableOutput().
OCI_EXPORT boolean OCI_API OCI_Prepare | ( | OCI_Statement * | stmt, |
const mtext * | sql | ||
) |
Prepare a SQL statement or PL/SQL block.
stmt | - Statement handle |
sql | - SQL order or PL/SQL block |
Definition at line 1952 of file statement.c.
References OCI_SetFetchSize(), and OCI_SetPrefetchSize().
Referenced by OCI_Describe(), OCI_DescribeFmt(), OCI_ExecuteStmt(), OCI_ExecuteStmtFmt(), OCI_ImmediateFmt(), OCI_Parse(), OCI_ParseFmt(), OCI_PrepareFmt(), OCI_QueueAlter(), OCI_QueueCreate(), OCI_QueueDrop(), OCI_QueueStart(), OCI_QueueStop(), OCI_QueueTableAlter(), OCI_QueueTableCreate(), OCI_QueueTableDrop(), OCI_QueueTableMigrate(), OCI_QueueTablePurge(), and OCI_ServerEnableOutput().
OCI_EXPORT boolean OCI_API OCI_Execute | ( | OCI_Statement * | stmt | ) |
Execute a prepared SQL statement or PL/SQL block.
stmt | - Statement handle |
Definition at line 2061 of file statement.c.
Referenced by OCI_QueueAlter(), OCI_QueueCreate(), OCI_QueueDrop(), OCI_QueueStart(), OCI_QueueStop(), OCI_QueueTableAlter(), OCI_QueueTableCreate(), OCI_QueueTableDrop(), OCI_QueueTableMigrate(), OCI_QueueTablePurge(), OCI_ServerEnableOutput(), OCI_ServerGetOutput(), and OCI_SubscriptionAddStatement().
OCI_EXPORT boolean OCI_API OCI_ExecuteStmt | ( | OCI_Statement * | stmt, |
const mtext * | sql | ||
) |
Execute a SQL statement or PL/SQL block.
stmt | - Statement handle |
sql | - SQL order - PL/SQL block |
Definition at line 2073 of file statement.c.
References OCI_Prepare().
Referenced by OCI_DatabaseShutdown(), OCI_DatabaseStartup(), OCI_Immediate(), and OCI_ServerDisableOutput().
OCI_EXPORT boolean OCI_API OCI_Parse | ( | OCI_Statement * | stmt, |
const mtext * | sql | ||
) |
Parse a SQL statement or PL/SQL block.
stmt | - Statement handle |
sql | - SQL order - PL/SQL block |
Definition at line 2086 of file statement.c.
References OCI_Prepare().
OCI_EXPORT boolean OCI_API OCI_Describe | ( | OCI_Statement * | stmt, |
const mtext * | sql | ||
) |
Describe the select list of a SQL select statement.
stmt | - Statement handle |
sql | - SELECT sql statement |
Definition at line 2099 of file statement.c.
References OCI_Prepare().
OCI_EXPORT const mtext* OCI_API OCI_GetSql | ( | OCI_Statement * | stmt | ) |
Return the last SQL or PL/SQL statement prepared or executed by the statement.
stmt | - Statement handle |
Definition at line 4135 of file statement.c.
OCI_EXPORT unsigned int OCI_API OCI_GetSqlErrorPos | ( | OCI_Statement * | stmt | ) |
Return the error position (in terms of characters) in the SQL statement where the error occurred in case of SQL parsing error.
stmt | - Statement handle |
Definition at line 4151 of file statement.c.
OCI_EXPORT unsigned int OCI_API OCI_GetAffectedRows | ( | OCI_Statement * | stmt | ) |
Return the number of rows affected by the SQL statement.
stmt | - Statement handle |
The returned value is :
Definition at line 4167 of file statement.c.
OCI_EXPORT unsigned int OCI_API OCI_GetSQLCommand | ( | OCI_Statement * | stmt | ) |
Return the Oracle SQL code the command held by the statement handle.
stmt | - Statement handle |
Definition at line 4258 of file statement.c.
Referenced by OCI_GetSQLVerb().
OCI_EXPORT const mtext* OCI_API OCI_GetSQLVerb | ( | OCI_Statement * | stmt | ) |
Return the verb of the SQL command held by the statement handle.
stmt | - Statement handle |
Definition at line 4287 of file statement.c.
References OCI_GetSQLCommand().