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 :
- OCI_ARG_SHORT ------> short *
- OCI_ARG_USHORT -----> unsigned short *
- OCI_ARG_INT --------> int *
- OCI_ARG_UINT -------> unsigned int*
- OCI_ARG_BIGINT -----> big_int *
- OCI_ARG_BIGUINT ----> unsigned big_int *
- OCI_ARG_DOUBLE ----> double *
- OCI_ARG_TEXT -------> dtext *
- OCI_ARG_RAW --------> void *
- OCI_ARG_DATETIME ---> OCI_Date *
- OCI_ARG_LOB --------> OCI_Lob *
- OCI_ARG_FILE -------> OCI_File *
- OCI_ARG_TIMESTAMP --> OCI_Timstamp *
- OCI_ARG_INTERVAL ---> OCI_Interval *
- OCI_ARG_OBJECT -----> OCI_Object *
- OCI_ARG_COLLECTION -> OCI_Coll *
- OCI_ARG_REF --------> OCI_Ref *
- 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.
- For strings, only the real string is copied.
- For Raws, the number of bytes copied is the column size
- Warning:
- Input parameters for formatted function only support a restricted set of datatypes !
Supported input identifiers :
- 's' : (dtext *) ----------> input string (quotes are added)
- 'm' : (dtext *) ----------> metadata string (no quotes added)
- 't' : (OCI_Date *) -------> Date
- 'p' : (OCI_Timestamp *) --> timestamp
- 'v' : (OCI_Interval *) ---> Interval
- 'i' : (int) --------------> signed 32 bits integer
- 'u' : (unsigned int) -----> unsigned 32 bits integer
- 'li' : (big_int) ----------> signed 64 bits integer
- 'lu' : (big_uint) ---------> unsigned 64 bits integer
- 'hi' : (short) ------------> signed 16 bits integer
- 'hu' : (unsigned short) ---> unsigned 16 bits integer
- 'g' : (double ) ----------> Numerics
- 'r' : (OCI_Ref *) --------> Reference
- 'o' : (OCI_Object *) -----> Object (not implemented yet)
- 'c' : (OCI_Coll *) -------> collection (not implemented yet)
- 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; }
댓글 없음:
댓글 쓰기