OCILIB (C Driver for Oracle) 3.9.1
|
00001 /* 00002 +-----------------------------------------------------------------------------------------+ 00003 | | 00004 | OCILIB - C Driver for Oracle | 00005 | | 00006 | (C Wrapper for Oracle OCI) | 00007 | | 00008 | Website : http://www.ocilib.net | 00009 | | 00010 | Copyright (c) 2007-2011 Vincent ROGIER <vince.rogier@ocilib.net> | 00011 | | 00012 +-----------------------------------------------------------------------------------------+ 00013 | | 00014 | This library is free software; you can redistribute it and/or | 00015 | modify it under the terms of the GNU Lesser General Public | 00016 | License as published by the Free Software Foundation; either | 00017 | version 2 of the License, or (at your option) any later version. | 00018 | | 00019 | This library is distributed in the hope that it will be useful, | 00020 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 00021 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 00022 | Lesser General Public License for more details. | 00023 | | 00024 | You should have received a copy of the GNU Lesser General Public | 00025 | License along with this library; if not, write to the Free | 00026 | Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | 00027 | | 00028 +-----------------------------------------------------------------------------------------+ 00029 */ 00030 00031 /* --------------------------------------------------------------------------------------------- * 00032 * $Id: event.c, v 3.9.1 2011-07-08 00:00 Vincent Rogier $ 00033 * --------------------------------------------------------------------------------------------- */ 00034 00035 #include "ocilib_internal.h" 00036 00037 /* ********************************************************************************************* * 00038 * PUBLIC FUNCTIONS 00039 * ********************************************************************************************* */ 00040 00041 /* --------------------------------------------------------------------------------------------- * 00042 * OCI_EnqueueCreate 00043 * --------------------------------------------------------------------------------------------- */ 00044 00045 OCI_Enqueue * OCI_API OCI_EnqueueCreate 00046 ( 00047 OCI_TypeInfo *typinf, 00048 const mtext *name 00049 ) 00050 { 00051 OCI_Enqueue *enqueue = NULL; 00052 boolean res = TRUE; 00053 00054 OCI_CHECK_INITIALIZED(NULL); 00055 00056 OCI_CHECK_PTR(OCI_IPC_TYPE_INFO, typinf, NULL); 00057 OCI_CHECK_PTR(OCI_IPC_STRING, name, NULL); 00058 00059 /* allocate enqueue structure */ 00060 00061 enqueue = (OCI_Enqueue *) OCI_MemAlloc(OCI_IPC_ENQUEUE, sizeof(*enqueue), (size_t) 1, TRUE); 00062 00063 if (enqueue != NULL) 00064 { 00065 enqueue->typinf = typinf; 00066 enqueue->name = mtsdup(name); 00067 00068 /* allocate enqueue options descriptor */ 00069 00070 res = (OCI_SUCCESS == OCI_DescriptorAlloc((dvoid * ) enqueue->typinf->con->env, 00071 (dvoid **) &enqueue->opth, 00072 OCI_DTYPE_AQENQ_OPTIONS, 00073 (size_t) 0, (dvoid **) NULL)); 00074 } 00075 else 00076 { 00077 res = FALSE; 00078 } 00079 00080 /* check for failure */ 00081 00082 if (res == FALSE) 00083 { 00084 OCI_EnqueueFree(enqueue); 00085 enqueue = NULL; 00086 } 00087 00088 return enqueue; 00089 } 00090 00091 /* --------------------------------------------------------------------------------------------- * 00092 * OCI_EnqueueFree 00093 * --------------------------------------------------------------------------------------------- */ 00094 00095 boolean OCI_API OCI_EnqueueFree 00096 ( 00097 OCI_Enqueue *enqueue 00098 ) 00099 { 00100 OCI_CHECK_PTR(OCI_IPC_ENQUEUE, enqueue, FALSE); 00101 00102 /* free OCI descriptor */ 00103 00104 OCI_DescriptorFree((dvoid *) enqueue->opth, OCI_DTYPE_AQENQ_OPTIONS); 00105 00106 OCI_FREE(enqueue->name); 00107 OCI_FREE(enqueue); 00108 00109 return TRUE; 00110 } 00111 00112 /* --------------------------------------------------------------------------------------------- * 00113 * OCI_EnqueuePut 00114 * --------------------------------------------------------------------------------------------- */ 00115 00116 boolean OCI_API OCI_EnqueuePut 00117 ( 00118 OCI_Enqueue *enqueue, 00119 OCI_Msg *msg 00120 ) 00121 { 00122 boolean res = TRUE; 00123 void *ostr = NULL; 00124 int osize = -1; 00125 00126 void *payload = NULL; 00127 void *ind = NULL; 00128 00129 OCI_CHECK_PTR(OCI_IPC_ENQUEUE, enqueue, FALSE); 00130 OCI_CHECK_PTR(OCI_IPC_MSG, msg, FALSE); 00131 00132 OCI_CHECK_COMPAT(enqueue->typinf->con, enqueue->typinf->tdo == msg->typinf->tdo, FALSE); 00133 00134 ostr = OCI_GetInputMetaString(enqueue->name, &osize); 00135 00136 /* get payload */ 00137 00138 if (enqueue->typinf->tcode != OCI_UNKNOWN) 00139 { 00140 if (msg->ind != OCI_IND_NULL) 00141 { 00142 payload = msg->obj->handle; 00143 ind = msg->obj->tab_ind; 00144 } 00145 } 00146 else 00147 { 00148 payload = msg->payload; 00149 ind = &msg->ind; 00150 } 00151 00152 /* enqueue message */ 00153 00154 OCI_CALL2 00155 ( 00156 res, enqueue->typinf->con, 00157 00158 OCIAQEnq(enqueue->typinf->con->cxt, enqueue->typinf->con->err, 00159 ostr, enqueue->opth, msg->proph, enqueue->typinf->tdo, 00160 &payload, &ind, NULL, OCI_DEFAULT); 00161 ) 00162 00163 OCI_ReleaseMetaString(ostr); 00164 00165 OCI_RESULT(res); 00166 00167 return res; 00168 } 00169 00170 /* --------------------------------------------------------------------------------------------- * 00171 * OCI_EnqueueGetVisibility 00172 * --------------------------------------------------------------------------------------------- */ 00173 00174 unsigned int OCI_API OCI_EnqueueGetVisibility 00175 ( 00176 OCI_Enqueue *enqueue 00177 ) 00178 { 00179 boolean res = TRUE; 00180 ub4 ret = 0; 00181 00182 OCI_CHECK_PTR(OCI_IPC_ENQUEUE, enqueue, FALSE); 00183 00184 OCI_CALL2 00185 ( 00186 res, enqueue->typinf->con, 00187 00188 OCIAttrGet((dvoid *) enqueue->opth, 00189 (ub4 ) OCI_DTYPE_AQENQ_OPTIONS, 00190 (dvoid *) &ret, 00191 (ub4 *) NULL, 00192 (ub4 ) OCI_ATTR_VISIBILITY, 00193 enqueue->typinf->con->err) 00194 ) 00195 00196 OCI_RESULT(res); 00197 00198 return (int) ret; 00199 } 00200 00201 /* --------------------------------------------------------------------------------------------- * 00202 * OCI_EnqueueSetVisibility 00203 * --------------------------------------------------------------------------------------------- */ 00204 00205 boolean OCI_API OCI_EnqueueSetVisibility 00206 ( 00207 OCI_Enqueue *enqueue, 00208 unsigned int visibility 00209 ) 00210 { 00211 boolean res = TRUE; 00212 ub4 value = (ub4) visibility; 00213 00214 OCI_CHECK_PTR(OCI_IPC_ENQUEUE, enqueue, FALSE); 00215 00216 OCI_CALL2 00217 ( 00218 res, enqueue->typinf->con, 00219 00220 OCIAttrSet((dvoid *) enqueue->opth, 00221 (ub4 ) OCI_DTYPE_AQENQ_OPTIONS, 00222 (dvoid *) &value, 00223 (ub4 ) 0, 00224 (ub4 ) OCI_ATTR_VISIBILITY, 00225 enqueue->typinf->con->err) 00226 ) 00227 00228 OCI_RESULT(res); 00229 00230 return res; 00231 } 00232 00233 /* --------------------------------------------------------------------------------------------- * 00234 * OCI_EnqueueGetSequenceDeviation 00235 * --------------------------------------------------------------------------------------------- */ 00236 00237 unsigned int OCI_API OCI_EnqueueGetSequenceDeviation 00238 ( 00239 OCI_Enqueue *enqueue 00240 ) 00241 { 00242 boolean res = TRUE; 00243 ub4 ret = 0; 00244 00245 OCI_CHECK_PTR(OCI_IPC_ENQUEUE, enqueue, FALSE); 00246 00247 OCI_CALL2 00248 ( 00249 res, enqueue->typinf->con, 00250 00251 OCIAttrGet((dvoid *) enqueue->opth, 00252 (ub4 ) OCI_DTYPE_AQENQ_OPTIONS, 00253 (dvoid *) &ret, 00254 (ub4 *) NULL, 00255 (ub4 ) OCI_ATTR_SEQUENCE_DEVIATION, 00256 enqueue->typinf->con->err) 00257 ) 00258 00259 OCI_RESULT(res); 00260 00261 return (int) ret; 00262 } 00263 00264 /* --------------------------------------------------------------------------------------------- * 00265 * OCI_EnqueueSetDeviation 00266 * --------------------------------------------------------------------------------------------- */ 00267 00268 boolean OCI_API OCI_EnqueueSetSequenceDeviation 00269 ( 00270 OCI_Enqueue *enqueue, 00271 unsigned int sequence 00272 ) 00273 { 00274 boolean res = TRUE; 00275 ub4 value = (ub4) sequence; 00276 00277 OCI_CHECK_PTR(OCI_IPC_ENQUEUE, enqueue, FALSE); 00278 00279 OCI_CALL2 00280 ( 00281 res, enqueue->typinf->con, 00282 00283 OCIAttrSet((dvoid *) enqueue->opth, 00284 (ub4 ) OCI_DTYPE_AQENQ_OPTIONS, 00285 (dvoid *) &value, 00286 (ub4 ) 0, 00287 (ub4 ) OCI_ATTR_SEQUENCE_DEVIATION, 00288 enqueue->typinf->con->err) 00289 ) 00290 00291 OCI_RESULT(res); 00292 00293 return res; 00294 } 00295 00296 /* --------------------------------------------------------------------------------------------- * 00297 * OCI_EnqueueSetRelativeMsgID 00298 * --------------------------------------------------------------------------------------------- */ 00299 00300 boolean OCI_API OCI_EnqueueGetRelativeMsgID 00301 ( 00302 OCI_Enqueue *enqueue, 00303 void *id, 00304 unsigned int *len 00305 ) 00306 { 00307 boolean res = TRUE; 00308 OCIRaw *value = NULL; 00309 00310 OCI_CHECK_PTR(OCI_IPC_ENQUEUE, enqueue, FALSE); 00311 OCI_CHECK_PTR(OCI_IPC_VOID, id, FALSE); 00312 OCI_CHECK_PTR(OCI_IPC_VOID, len, FALSE); 00313 00314 OCI_CALL2 00315 ( 00316 res, enqueue->typinf->con, 00317 00318 OCIAttrGet((dvoid *) enqueue->opth, 00319 (ub4 ) OCI_DTYPE_AQENQ_OPTIONS, 00320 (dvoid *) &value, 00321 (ub4 *) NULL, 00322 (ub4 ) OCI_ATTR_RELATIVE_MSGID, 00323 enqueue->typinf->con->err) 00324 ) 00325 00326 if (value != NULL) 00327 { 00328 ub4 raw_len = 0; 00329 00330 raw_len = OCIRawSize(enqueue->typinf->con->env, value); 00331 00332 if (*len > raw_len) 00333 *len = raw_len; 00334 00335 memcpy(id, OCIRawPtr(enqueue->typinf->con->env, value), (size_t) (*len)); 00336 } 00337 else 00338 { 00339 *len = 0; 00340 } 00341 00342 OCI_RESULT(res); 00343 00344 return res; 00345 } 00346 00347 /* --------------------------------------------------------------------------------------------- * 00348 * OCI_EnqueueSetRelativeMsgID 00349 * --------------------------------------------------------------------------------------------- */ 00350 00351 boolean OCI_API OCI_EnqueueSetRelativeMsgID 00352 ( 00353 OCI_Enqueue *enqueue, 00354 const void *id, 00355 unsigned int len 00356 ) 00357 { 00358 boolean res = TRUE; 00359 OCIRaw *value = NULL; 00360 00361 OCI_CHECK_PTR(OCI_IPC_ENQUEUE, enqueue, FALSE); 00362 00363 OCI_CALL2 00364 ( 00365 res, enqueue->typinf->con, 00366 00367 OCIRawAssignBytes(enqueue->typinf->con->env, enqueue->typinf->con->err, 00368 (ub1*) id, (ub4) len, (OCIRaw **) &value) 00369 ) 00370 00371 OCI_CALL2 00372 ( 00373 res, enqueue->typinf->con, 00374 00375 OCIAttrSet((dvoid *) enqueue->opth, 00376 (ub4 ) OCI_DTYPE_AQENQ_OPTIONS, 00377 (dvoid *) &value, 00378 (ub4 ) 0, 00379 (ub4 ) OCI_ATTR_RELATIVE_MSGID, 00380 enqueue->typinf->con->err) 00381 ) 00382 00383 OCI_RESULT(res); 00384 00385 return res; 00386 } 00387