00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #include "ocilib_internal.h"
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 OCI_Coll * OCI_CollInit
00046 (
00047 OCI_Connection *con,
00048 OCI_Coll **pcoll,
00049 void *handle,
00050 OCI_TypeInfo *typinf
00051 )
00052 {
00053 OCI_Coll *coll = NULL;
00054 boolean res = TRUE;
00055
00056 OCI_CHECK(pcoll == NULL, NULL);
00057
00058 if (*pcoll == NULL)
00059 *pcoll = (OCI_Coll *) OCI_MemAlloc(OCI_IPC_COLLECTION, sizeof(*coll),
00060 (size_t) 1, TRUE);
00061
00062 if (*pcoll != NULL)
00063 {
00064 coll = *pcoll;
00065
00066 coll->con = con;
00067 coll->handle = handle;
00068 coll->typinf = typinf;
00069
00070 if ((coll->handle == NULL) || (coll->hstate == OCI_OBJECT_ALLOCATED_ARRAY))
00071 {
00072
00073
00074 if (coll->hstate != OCI_OBJECT_ALLOCATED_ARRAY)
00075 {
00076 coll->hstate = OCI_OBJECT_ALLOCATED;
00077 }
00078
00079 OCI_CALL2
00080 (
00081 res, con,
00082
00083 OCI_ObjectNew(OCILib.env, con->err, con->cxt, typinf->ccode,
00084 typinf->tdo, (void *) NULL, OCI_DURATION_SESSION,
00085 TRUE, (dvoid **) &coll->handle)
00086 )
00087 }
00088 else
00089 coll->hstate = OCI_OBJECT_FETCHED_CLEAN;
00090 }
00091 else
00092 res = FALSE;
00093
00094
00095
00096 if (res == FALSE)
00097 {
00098 OCI_CollFree(coll);
00099 coll = NULL;
00100 }
00101
00102 return coll;
00103 }
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113 OCI_Coll * OCI_API OCI_CollCreate
00114 (
00115 OCI_TypeInfo *typinf
00116 )
00117 {
00118 OCI_Coll *coll = NULL;
00119
00120 OCI_CHECK_INITIALIZED(NULL);
00121
00122 OCI_CHECK_PTR(OCI_IPC_TYPE_INFO, typinf, NULL);
00123 OCI_CHECK(typinf->ccode == OCI_UNKNOWN, NULL)
00124
00125 coll = OCI_CollInit(typinf->con, &coll, (OCIColl *) NULL, typinf);
00126
00127 OCI_RESULT(coll != NULL);
00128
00129 return coll;
00130 }
00131
00132
00133
00134
00135
00136 boolean OCI_API OCI_CollFree
00137 (
00138 OCI_Coll *coll
00139 )
00140 {
00141 OCI_CHECK_PTR(OCI_IPC_COLLECTION, coll, FALSE);
00142 OCI_CHECK_OBJECT_FETCHED(coll, FALSE);
00143
00144
00145
00146 if (coll->elem != NULL)
00147 {
00148 coll->elem->hstate = OCI_OBJECT_FETCHED_DIRTY;
00149 OCI_ElemFree(coll->elem);
00150 coll->elem = NULL;
00151 }
00152
00153
00154
00155 if ((coll->hstate == OCI_OBJECT_ALLOCATED ) ||
00156 (coll->hstate == OCI_OBJECT_ALLOCATED_ARRAY))
00157 {
00158 OCI_OCIObjectFree(OCILib.env, coll->typinf->con->err,
00159 coll->handle, OCI_OBJECTFREE_NONULL);
00160 }
00161
00162 if (coll->hstate != OCI_OBJECT_ALLOCATED_ARRAY)
00163 {
00164 OCI_FREE(coll);
00165 }
00166
00167 OCI_RESULT(TRUE);
00168
00169 return TRUE;
00170 }
00171
00172
00173
00174
00175
00176 OCI_Coll ** OCI_API OCI_CollArrayCreate
00177 (
00178 OCI_Connection *con,
00179 OCI_TypeInfo *typinf,
00180 unsigned int nbelem
00181 )
00182 {
00183 OCI_Array *arr = NULL;
00184 OCI_Coll **colls = NULL;
00185
00186 arr = OCI_ArrayCreate(con, nbelem, OCI_CDT_COLLECTION, 0,
00187 sizeof(OCIColl *), sizeof(OCI_Coll),
00188 0, typinf);
00189
00190 if (arr != NULL)
00191 {
00192 colls = (OCI_Coll **) arr->tab_obj;
00193 }
00194
00195 return colls;
00196 }
00197
00198
00199
00200
00201
00202 boolean OCI_API OCI_CollArrayFree
00203 (
00204 OCI_Coll **colls
00205 )
00206 {
00207 return OCI_ArrayFreeFromHandles((void **) colls);
00208 }
00209
00210
00211
00212
00213
00214 boolean OCI_API OCI_CollAssign
00215 (
00216 OCI_Coll *coll,
00217 OCI_Coll *coll_src
00218 )
00219 {
00220 boolean res = TRUE;
00221
00222 OCI_CHECK_PTR(OCI_IPC_COLLECTION, coll, FALSE);
00223 OCI_CHECK_PTR(OCI_IPC_COLLECTION, coll_src, FALSE);
00224
00225 OCI_CHECK_COMPAT(coll->con,
00226 coll->typinf->cols[0].icode == coll_src->typinf->cols[0].icode,
00227 FALSE);
00228
00229 OCI_CALL2
00230 (
00231 res, coll->con,
00232
00233 OCICollAssign(OCILib.env, coll->con->err, coll_src->handle, coll->handle)
00234 )
00235
00236 OCI_RESULT(res);
00237
00238 return res;
00239 }
00240
00241
00242
00243
00244
00245 unsigned int OCI_API OCI_CollGetType
00246 (
00247 OCI_Coll *coll
00248 )
00249 {
00250 unsigned int type = OCI_UNKNOWN;
00251
00252 OCI_CHECK_PTR(OCI_IPC_COLLECTION, coll, OCI_UNKNOWN);
00253
00254 if (coll->typinf->ccode == OCI_TYPECODE_TABLE)
00255 type = OCI_COLL_NESTED_TABLE;
00256 else if(coll->typinf->ccode == OCI_TYPECODE_VARRAY)
00257 type = OCI_COLL_VARRAY;
00258
00259 OCI_RESULT(TRUE);
00260
00261 return type;
00262 }
00263
00264
00265
00266
00267
00268 unsigned int OCI_API OCI_CollGetMax
00269 (
00270 OCI_Coll *coll
00271 )
00272 {
00273 int max = 0;
00274
00275 OCI_CHECK_PTR(OCI_IPC_COLLECTION, coll, 0);
00276
00277 max = OCICollMax(OCILib.env, coll->handle);
00278
00279 OCI_RESULT(TRUE);
00280
00281 return (unsigned int) max;
00282 }
00283
00284
00285
00286
00287
00288 unsigned int OCI_API OCI_CollGetSize
00289 (
00290 OCI_Coll *coll
00291 )
00292 {
00293 boolean res = TRUE;
00294 sb4 size = 0;
00295
00296 OCI_CHECK_PTR(OCI_IPC_COLLECTION, coll, 0);
00297
00298 OCI_CALL2
00299 (
00300 res, coll->con,
00301
00302 OCICollSize(OCILib.env, coll->con->err, coll->handle, &size)
00303 )
00304
00305 OCI_RESULT(res);
00306
00307 return (unsigned int) size;
00308 }
00309
00310
00311
00312
00313
00314 boolean OCI_API OCI_CollTrim
00315 (
00316 OCI_Coll *coll,
00317 unsigned int nb_elem
00318 )
00319 {
00320 boolean res = TRUE;
00321 unsigned int size = 0;
00322
00323 OCI_CHECK_PTR(OCI_IPC_COLLECTION, coll, FALSE);
00324
00325 size = OCI_CollGetSize(coll);
00326
00327 OCI_CHECK_BOUND(coll->con, (sb4) nb_elem, (sb4) 0, (sb4) size, FALSE);
00328
00329 OCI_CALL2
00330 (
00331 res, coll->con,
00332
00333 OCICollTrim(OCILib.env, coll->con->err, (sb4) nb_elem, coll->handle)
00334 )
00335
00336 OCI_RESULT(res);
00337
00338 return res;
00339 }
00340
00341
00342
00343
00344
00345 OCI_Elem * OCI_API OCI_CollGetAt
00346 (
00347 OCI_Coll *coll,
00348 unsigned int index
00349 )
00350 {
00351 boolean res = TRUE;
00352 boolean exists = FALSE;
00353 void *data = NULL;
00354 OCIInd *p_ind = NULL;
00355 OCI_Elem *elem = NULL;
00356
00357 OCI_CHECK_PTR(OCI_IPC_COLLECTION, coll, NULL);
00358
00359 OCI_CALL2
00360 (
00361 res, coll->con,
00362
00363 OCICollGetElem(OCILib.env, coll->con->err, coll->handle, (sb4) index-1,
00364 &exists, &data, (dvoid **) (dvoid *) &p_ind)
00365 )
00366
00367 if (res == TRUE && exists == TRUE && data != NULL)
00368 {
00369 elem = coll->elem = OCI_ElemInit(coll->con, &coll->elem,
00370 data, p_ind, coll->typinf);
00371 }
00372
00373 OCI_RESULT(res);
00374
00375 return elem;
00376 }
00377
00378
00379
00380
00381
00382 boolean OCI_API OCI_CollGetAt2
00383 (
00384 OCI_Coll *coll,
00385 unsigned int index,
00386 OCI_Elem *elem
00387 )
00388 {
00389 boolean res = TRUE;
00390 boolean exists = FALSE;
00391 void *data = NULL;
00392 OCIInd *p_ind = NULL;
00393
00394 OCI_CHECK_PTR(OCI_IPC_COLLECTION, coll, FALSE);
00395 OCI_CHECK_PTR(OCI_IPC_ELEMENT, elem, FALSE);
00396
00397 OCI_CHECK_COMPAT(coll->con,
00398 elem->typinf->cols[0].type == coll->typinf->cols[0].type,
00399 FALSE);
00400
00401 OCI_CALL2
00402 (
00403 res, coll->con,
00404
00405 OCICollGetElem(OCILib.env, coll->con->err, coll->handle, (sb4) index-1,
00406 &exists, &data, (dvoid **) (dvoid *) &p_ind)
00407 )
00408
00409 if (res == TRUE && exists == TRUE && data != NULL)
00410 {
00411 res = (OCI_ElemInit(coll->con, &elem, data, p_ind, coll->typinf) != NULL);
00412 }
00413 else
00414 {
00415 OCI_ElemSetNullIndicator(elem, OCI_IND_NULL);
00416 }
00417
00418 OCI_RESULT(res);
00419
00420 return res;
00421 }
00422
00423
00424
00425
00426
00427 boolean OCI_API OCI_CollSetAt
00428 (
00429 OCI_Coll *coll,
00430 unsigned int index,
00431 OCI_Elem *elem
00432 )
00433 {
00434 boolean res = TRUE;
00435
00436 OCI_CHECK_PTR(OCI_IPC_COLLECTION, coll, FALSE);
00437 OCI_CHECK_PTR(OCI_IPC_ELEMENT, elem, FALSE);
00438
00439 OCI_CHECK_COMPAT(coll->con,
00440 elem->typinf->cols[0].type == coll->typinf->cols[0].type,
00441 FALSE);
00442
00443 OCI_CALL2
00444 (
00445 res, coll->con,
00446
00447 OCICollAssignElem(OCILib.env, coll->con->err, (sb4) index-1, elem->handle,
00448 elem->pind,coll->handle)
00449 )
00450
00451 OCI_RESULT(res);
00452
00453 return res;
00454 }
00455
00456
00457
00458
00459
00460 boolean OCI_API OCI_CollAppend
00461 (
00462 OCI_Coll *coll,
00463 OCI_Elem *elem
00464 )
00465 {
00466 boolean res = TRUE;
00467
00468 OCI_CHECK_PTR(OCI_IPC_COLLECTION, coll, FALSE);
00469 OCI_CHECK_PTR(OCI_IPC_ELEMENT, elem, FALSE);
00470
00471 OCI_CHECK_COMPAT(coll->con,
00472 elem->typinf->cols[0].type == coll->typinf->cols[0].type,
00473 FALSE);
00474
00475 OCI_CALL2
00476 (
00477 res, coll->con,
00478
00479 OCICollAppend(OCILib.env, coll->con->err, elem->handle, elem->pind,
00480 coll->handle)
00481 )
00482
00483 OCI_RESULT(res);
00484
00485 return res;
00486 }
00487
00488
00489
00490
00491
00492 OCI_TypeInfo * OCI_API OCI_CollGetTypeInfo
00493 (
00494 OCI_Coll *coll
00495 )
00496 {
00497 OCI_CHECK_PTR(OCI_IPC_COLLECTION, coll, NULL);
00498
00499 OCI_RESULT(TRUE);
00500
00501 return coll->typinf;
00502 }
00503
00504
00505
00506
00507
00508 boolean OCI_API OCI_CollClear
00509 (
00510 OCI_Coll *coll
00511 )
00512 {
00513 boolean res = TRUE;
00514
00515 unsigned int size = OCI_CollGetSize(coll);
00516
00517 if (size > 0)
00518 {
00519 res = OCI_CollTrim(coll, size);
00520 }
00521
00522 OCI_RESULT(res);
00523
00524 return res;
00525 }
00526