Tang Cheng | 03c0b0a | 2015-01-12 11:19:45 +0800 | [diff] [blame^] | 1 | /* |
| 2 | * |
| 3 | */ |
| 4 | |
| 5 | /* Copyright (c) 1996, 2005, Oracle. All rights reserved. */ |
| 6 | |
| 7 | /* |
| 8 | NAME |
| 9 | ociextp.h - Interface Definitions for PL/SQL External Procedures |
| 10 | |
| 11 | DESCRIPTION |
| 12 | This header file contains C language callable interface from |
| 13 | PL/SQL External Procedures. |
| 14 | |
| 15 | PUBLIC FUNCTION(S) |
| 16 | OCIExtProcAllocCallMemory - Allocate Call memory |
| 17 | OCIExtProcRaiseExcp - Raise Exception |
| 18 | OCIExtProcRaiseExcpWithMsg - Raise Exception with message |
| 19 | OCIExtProcGetEnv - Get OCI Environment |
| 20 | |
| 21 | PRIVATE FUNCTION(S) |
| 22 | <list of static functions defined in .c file - with one-line descriptions> |
| 23 | |
| 24 | EXAMPLES |
| 25 | |
| 26 | NOTES |
| 27 | <other useful comments, qualifications, etc.> |
| 28 | |
| 29 | MODIFIED (MM/DD/YY) |
| 30 | dmukhin 06/29/05 - ANSI prototypes; miscellaneous cleanup |
| 31 | srseshad 03/12/03 - convert oci public api to ansi |
| 32 | rdecker 01/10/02 - change 32k to MAX_OEN for error numbers |
| 33 | sagrawal 07/20/01 - Statement Handle to safe cal outs |
| 34 | abrumm 04/19/01 - move include of oci.h after defines/typedef |
| 35 | rdecker 02/22/01 - lint fix |
| 36 | bpalaval 02/08/01 - Change text to oratext. |
| 37 | sagrawal 06/16/00 - ref cursor in callouts |
| 38 | whe 09/01/99 - 976457:check __cplusplus for C++ code |
| 39 | asethi 04/15/99 - Created (by moving ociextp.h from /vobs/plsql/public) |
| 40 | rhari 03/25/97 - Use ifndef |
| 41 | rhari 12/18/96 - Include oratypes.h |
| 42 | rhari 12/11/96 - #416977, Flip values of return codes |
| 43 | rhari 12/02/96 - Define Return Code Macros |
| 44 | rhari 11/18/96 - Error number is int |
| 45 | rhari 10/30/96 - Fix OCIExtProcRaiseExcpWithMsg |
| 46 | rhari 10/30/96 - Get rid of warnings |
| 47 | rhari 10/04/96 - Fix OCIExtProcRaiseExcpWithMsg |
| 48 | rhari 09/23/96 - Creation |
| 49 | |
| 50 | */ |
| 51 | |
| 52 | |
| 53 | #ifndef OCIEXTP_ORACLE |
| 54 | # define OCIEXTP_ORACLE |
| 55 | |
| 56 | # ifndef ORATYPES |
| 57 | # include <oratypes.h> |
| 58 | # endif |
| 59 | |
| 60 | |
| 61 | /*--------------------------------------------------------------------------- |
| 62 | PUBLIC TYPES AND CONSTANTS |
| 63 | ---------------------------------------------------------------------------*/ |
| 64 | |
| 65 | |
| 66 | /* ----------------------------- Return Codes ----------------------------- */ |
| 67 | /* Success and Error return codes for certain external procedure interface |
| 68 | * functions. If a particular interface function returns OCIEXTPROC_SUCCESS |
| 69 | * or OCIEXTPROC_ERROR, then applications must use these macros to check |
| 70 | * for return values. |
| 71 | * |
| 72 | * OCIEXTPROC_SUCCESS -- External Procedure Success Return Code |
| 73 | * OCIEXTPROC_ERROR -- External Procedure Failure Return Code |
| 74 | */ |
| 75 | #define OCIEXTPROC_SUCCESS 0 |
| 76 | #define OCIEXTPROC_ERROR 1 |
| 77 | |
| 78 | |
| 79 | /* --------------------------- With-Context Type --------------------------- */ |
| 80 | /* |
| 81 | * The C callable interface to PL/SQL External Procedures require the |
| 82 | * With-Context parameter to be passed. The type of this structure is |
| 83 | * OCIExtProcContext is is opaque to the user. |
| 84 | * |
| 85 | * The user can declare the With-Context parameter in the application as |
| 86 | * |
| 87 | * OCIExtProcContext *with_context; |
| 88 | */ |
| 89 | typedef struct OCIExtProcContext OCIExtProcContext; |
| 90 | |
| 91 | /* NOTE: OCIExtProcContext must be visible prior to including <oci.h> */ |
| 92 | |
| 93 | # ifndef OCI_ORACLE |
| 94 | # include <oci.h> |
| 95 | # endif |
| 96 | |
| 97 | |
| 98 | /* ----------------------- OCIExtProcAllocCallMemory ----------------------- */ |
| 99 | /* OCIExtProcAllocCallMemory |
| 100 | * Allocate N bytes of memory for the duration of the External Procedure. |
| 101 | * |
| 102 | * Memory thus allocated will be freed by PL/SQL upon return from the |
| 103 | * External Procedure. You must not use any kind of 'free' function on |
| 104 | * memory allocated by OCIExtProcAllocCallMemory. |
| 105 | * Use this function to allocate memory for function returns. |
| 106 | * |
| 107 | * PARAMETERS |
| 108 | * Input : |
| 109 | * with_context - The with_context pointer that is passed to the C |
| 110 | * External Procedure. |
| 111 | * Type of with_context : OCIExtProcContext * |
| 112 | * amount - The number of bytes to allocate. |
| 113 | * Type of amount : size_t |
| 114 | * |
| 115 | * Output : |
| 116 | * Nothing |
| 117 | * |
| 118 | * Return : |
| 119 | * An untyped (opaque) Pointer to the allocated memory. |
| 120 | * |
| 121 | * Errors : |
| 122 | * A 0 return value should be treated as an error |
| 123 | * |
| 124 | * EXAMPLE |
| 125 | * text *ptr = (text *)OCIExtProcAllocCallMemory(wctx, 1024) |
| 126 | * |
| 127 | */ |
| 128 | #define OCIExtProcAllocCallMemory(with_context, amount) \ |
| 129 | ociepacm(with_context, (size_t)amount) |
| 130 | |
| 131 | |
| 132 | |
| 133 | |
| 134 | /* -------------------------- OCIExtProcRaiseExcp -------------------------- */ |
| 135 | /* OCIExtProcRaiseExcp |
| 136 | * Raise an Exception to PL/SQL. |
| 137 | * |
| 138 | * Calling this function signalls an exception back to PL/SQL. After a |
| 139 | * successful return from this function, the External Procedure must start |
| 140 | * its exit handling and return back to PL/SQL. Once an exception is |
| 141 | * signalled to PL/SQL, INOUT and OUT arguments, if any, are not processed |
| 142 | * at all. |
| 143 | * |
| 144 | * PARAMETERS |
| 145 | * Input : |
| 146 | * with_context - The with_context pointer that is passed to the C |
| 147 | * External Procedure. |
| 148 | * Type of with_context : OCIExtProcContext * |
| 149 | * errnum - Oracle Error number to signal to PL/SQL. errnum |
| 150 | * must be a positive number and in the range 1 to MAX_OEN |
| 151 | * Type of errnum : int |
| 152 | * Output : |
| 153 | * Nothing |
| 154 | * |
| 155 | * Return : |
| 156 | * OCIEXTPROC_SUCCESS - If the call was successful. |
| 157 | * OCIEXTPROC_ERROR - If the call failed. |
| 158 | * |
| 159 | */ |
| 160 | #define OCIExtProcRaiseExcp(with_context, errnum) \ |
| 161 | ocieperr(with_context, (int)errnum) |
| 162 | |
| 163 | |
| 164 | |
| 165 | |
| 166 | |
| 167 | /* ---------------------- OCIExtProcRaiseExcpWithMsg ---------------------- */ |
| 168 | /* OCIExtProcRaiseExcpWithMsg |
| 169 | * Raise an exception to PL/SQL. In addition, substitute the |
| 170 | * following error message string within the standard Oracle error |
| 171 | * message string. See note for OCIExtProcRaiseExcp |
| 172 | * |
| 173 | * PARAMETERS |
| 174 | * Input : |
| 175 | * with_context - The with_context pointer that is passed to the C |
| 176 | * External Procedure. |
| 177 | * Type of with_context : OCIExtProcContext * |
| 178 | * errnum - Oracle Error number to signal to PL/SQL. errnum |
| 179 | * must be a positive number and in the range 1 to MAX_OEN |
| 180 | * Type of errnum : int |
| 181 | * errmsg - The error message associated with the errnum. |
| 182 | * Type of errmsg : char * |
| 183 | * len - The length of the error message. 0 if errmsg is |
| 184 | * null terminated string. |
| 185 | * Type of len : size_t |
| 186 | * Output : |
| 187 | * Nothing |
| 188 | * |
| 189 | * Return : |
| 190 | * OCIEXTPROC_SUCCESS - If the call was successful. |
| 191 | * OCIEXTPROC_ERROR - If the call failed. |
| 192 | * |
| 193 | */ |
| 194 | #define OCIExtProcRaiseExcpWithMsg(with_context, errnum, errmsg, msglen) \ |
| 195 | ociepmsg(with_context, (int)errnum, errmsg, (size_t)msglen) |
| 196 | |
| 197 | |
| 198 | |
| 199 | /* --------------------------- OCIExtProcGetEnv --------------------------- */ |
| 200 | /* OCIExtProcGetEnv |
| 201 | * Get OCI Environment |
| 202 | * |
| 203 | * PARAMETERS |
| 204 | * Input : |
| 205 | * with_context - The with_context pointer that is passed to the C |
| 206 | * External Procedure. |
| 207 | * |
| 208 | * Output : |
| 209 | * envh - The OCI Environment handle. |
| 210 | * svch - The OCI Service handle. |
| 211 | * errh - The OCI Error handle. |
| 212 | * |
| 213 | * Return : |
| 214 | * OCI_SUCCESS - Successful completion of the function. |
| 215 | * OCI_ERROR - Error. |
| 216 | * |
| 217 | */ |
| 218 | #define OCIExtProcGetEnv(with_context, envh, svch, errh) \ |
| 219 | ociepgoe(with_context, envh, svch, errh) |
| 220 | |
| 221 | |
| 222 | |
| 223 | /* ------------------------ OCIInitializeStatementHandle ------------------- */ |
| 224 | /* OCIreateStatementHandle |
| 225 | * Initialize Statement Handle |
| 226 | * |
| 227 | * PARAMETERS |
| 228 | * Input : |
| 229 | * wctx - The |
| 230 | * cursorno - The cursor number for which we need to initialize |
| 231 | * the statement handle |
| 232 | * svch - The OCI Service handle. |
| 233 | * |
| 234 | * Output : |
| 235 | * stmthp - The OCI Statement handle. |
| 236 | * errh - The OCI Error handle. |
| 237 | * |
| 238 | * Return : |
| 239 | * OCI_SUCCESS - Successful completion of the function. |
| 240 | * OCI_ERROR - Error. |
| 241 | * |
| 242 | */ |
| 243 | #define OCIInitializeStatementHandle(wctx, cursorno, svch, stmthp, errh) \ |
| 244 | ociepish(wctx, cursor, svch, stmthp, errh) |
| 245 | |
| 246 | |
| 247 | |
| 248 | |
| 249 | /*--------------------------------------------------------------------------- |
| 250 | PRIVATE TYPES AND CONSTANTS |
| 251 | ---------------------------------------------------------------------------*/ |
| 252 | |
| 253 | |
| 254 | /*--------------------------------------------------------------------------- |
| 255 | PUBLIC FUNCTIONS |
| 256 | ---------------------------------------------------------------------------*/ |
| 257 | |
| 258 | |
| 259 | /*--------------------------------------------------------------------------- |
| 260 | PRIVATE FUNCTIONS |
| 261 | ---------------------------------------------------------------------------*/ |
| 262 | |
| 263 | |
| 264 | |
| 265 | void *ociepacm(OCIExtProcContext *with_context, size_t amount); |
| 266 | |
| 267 | |
| 268 | |
| 269 | size_t ocieperr(OCIExtProcContext *with_context, int error_number); |
| 270 | |
| 271 | |
| 272 | |
| 273 | size_t ociepmsg(OCIExtProcContext *with_context, int error_number, |
| 274 | oratext *error_message, size_t len ); |
| 275 | |
| 276 | |
| 277 | |
| 278 | sword ociepgoe(OCIExtProcContext *with_context, OCIEnv **envh, |
| 279 | OCISvcCtx **svch, OCIError **errh); |
| 280 | |
| 281 | |
| 282 | #endif /* OCIEXTP_ORACLE */ |