• Main Page
  • Modules
  • Data Structures
  • Files
  • File List

D:/Perso/dev/ocilib/ocilib/src/iterator.c

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-2010 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: iterator.c, v 3.8.1 2010-12-13 00:00 Vincent Rogier $
00033  * --------------------------------------------------------------------------------------------- */
00034 
00035 #include "ocilib_internal.h"
00036 
00037 /* ********************************************************************************************* *
00038  *                            PUBLIC FUNCTIONS
00039  * ********************************************************************************************* */
00040 
00041 /* --------------------------------------------------------------------------------------------- *
00042  * OCI_IterCreate
00043  * --------------------------------------------------------------------------------------------- */
00044 
00045 OCI_Iter * OCI_API OCI_IterCreate
00046 (
00047     OCI_Coll *coll
00048 )
00049 {
00050     boolean res    = TRUE;
00051     OCI_Iter *iter = NULL;
00052 
00053     OCI_CHECK_INITIALIZED(NULL);
00054 
00055     OCI_CHECK_PTR(OCI_IPC_COLLECTION, coll, NULL);
00056 
00057     /* allocate iterator structure */
00058 
00059     iter = (OCI_Iter *) OCI_MemAlloc(OCI_IPC_ITERATOR, sizeof(*iter),
00060                                      (size_t) 1, TRUE);
00061 
00062     if (iter != NULL)
00063     {
00064         iter->coll = coll;
00065         iter->eoc  = FALSE;
00066         iter->boc  = TRUE;
00067 
00068         /* create iterator */
00069 
00070         OCI_CALL2
00071         (
00072             res, iter->coll->con,
00073 
00074             OCIIterCreate(OCILib.env, iter->coll->con->err, coll->handle,
00075                           &iter->handle)
00076         )
00077 
00078         /* create data element accessor */
00079 
00080         if (res == TRUE)
00081             iter->elem = OCI_ElemInit(coll->con, &iter->elem, NULL,
00082                                       (OCIInd *) NULL, coll->typinf);
00083 
00084         if (res == TRUE)
00085             res = (iter->elem != NULL);
00086 
00087     }
00088     else
00089         res = FALSE;
00090 
00091     /* check for success */
00092 
00093     if (res == FALSE)
00094     {
00095         OCI_IterFree(iter);
00096         iter = NULL;
00097     }
00098 
00099     OCI_RESULT(res);
00100 
00101     return iter;
00102 }
00103 
00104 /* --------------------------------------------------------------------------------------------- *
00105  * OCI_IterFree
00106  * --------------------------------------------------------------------------------------------- */
00107 
00108 boolean OCI_API OCI_IterFree
00109 (
00110     OCI_Iter *iter
00111 )
00112 {
00113     boolean res = TRUE;
00114 
00115     OCI_CHECK_PTR(OCI_IPC_ITERATOR, iter, FALSE);
00116 
00117     /* close iterator handle */
00118 
00119     if (iter->handle != NULL)
00120     {
00121         OCI_CALL2
00122         (
00123             res, iter->coll->con,
00124 
00125             OCIIterDelete(OCILib.env, iter->coll->con->err, &iter->handle)
00126         )
00127     }
00128 
00129     /* free data element accessor */
00130 
00131     if (iter->elem != NULL)
00132     {
00133         iter->elem->hstate = OCI_OBJECT_FETCHED_DIRTY;
00134         OCI_ElemFree(iter->elem);
00135         iter->elem = NULL;
00136     }
00137 
00138     /* free iterator structure */
00139 
00140     OCI_FREE(iter);
00141 
00142     OCI_RESULT(res);
00143 
00144     return res;
00145 }
00146 
00147 /* --------------------------------------------------------------------------------------------- *
00148  * OCI_IterGetNext
00149  * --------------------------------------------------------------------------------------------- */
00150 
00151 OCI_Elem * OCI_API OCI_IterGetNext
00152 (
00153     OCI_Iter *iter
00154 )
00155 {
00156     boolean res    = TRUE;
00157     OCI_Elem *elem = NULL;
00158     void * data    = NULL;
00159     void *p_ind    = NULL;
00160 
00161     OCI_CHECK_PTR(OCI_IPC_ITERATOR, iter, NULL);
00162 
00163     OCI_CHECK(iter->eoc == TRUE, NULL);
00164 
00165     OCI_CALL2
00166     (
00167         res, iter->coll->con,
00168 
00169         OCIIterNext(OCILib.env, iter->coll->con->err, iter->handle,
00170                     &data, (dvoid **) &p_ind, &iter->eoc)
00171     )
00172 
00173     if ((res == TRUE) && (iter->eoc == FALSE))
00174     {
00175         elem = OCI_ElemInit(iter->coll->con, &iter->elem,
00176                             data, p_ind, iter->coll->typinf);
00177     }
00178 
00179     OCI_RESULT(elem != NULL);
00180 
00181     return elem;
00182 }
00183 
00184 /* --------------------------------------------------------------------------------------------- *
00185  * OCI_IterGetPrev
00186  * --------------------------------------------------------------------------------------------- */
00187 
00188 OCI_Elem * OCI_API OCI_IterGetPrev
00189 (
00190     OCI_Iter *iter
00191 )
00192 {
00193     boolean res    = TRUE;
00194     OCI_Elem *elem = NULL;
00195     void * data    = NULL;
00196     void *p_ind    = NULL;
00197 
00198     OCI_CHECK_PTR(OCI_IPC_ITERATOR, iter, NULL);
00199 
00200     OCI_CHECK(iter->boc == TRUE, NULL);
00201 
00202     OCI_CALL2
00203     (
00204         res, iter->coll->con,
00205 
00206         OCIIterPrev(OCILib.env, iter->coll->con->err, iter->handle,
00207                     &data, (dvoid **) &p_ind, &iter->boc)
00208     )
00209 
00210     if ((res == TRUE) && (iter->boc == FALSE))
00211     {
00212         elem = OCI_ElemInit(iter->coll->con, &iter->elem,
00213                             data, p_ind, iter->coll->typinf);
00214     }
00215 
00216     OCI_RESULT(elem != NULL);
00217 
00218     return elem;
00219 
00220 }

Generated on Mon Dec 13 2010 22:32:01 for OCILIB (C Driver for Oracle) by  doxygen 1.7.2