• 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.0 2010-10-24 21:53 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         res        = OCI_ElemFree(iter->elem);
00134         iter->elem = NULL;
00135     }
00136 
00137     /* free iterator structure */
00138 
00139     OCI_FREE(iter);
00140 
00141     OCI_RESULT(res);
00142 
00143     return res;
00144 }
00145 
00146 /* --------------------------------------------------------------------------------------------- *
00147  * OCI_IterGetNext
00148  * --------------------------------------------------------------------------------------------- */
00149 
00150 OCI_Elem * OCI_API OCI_IterGetNext
00151 (
00152     OCI_Iter *iter
00153 )
00154 {
00155     boolean res    = TRUE;
00156     OCI_Elem *elem = NULL;
00157     void * data    = NULL;
00158     void *p_ind    = NULL;
00159 
00160     OCI_CHECK_PTR(OCI_IPC_ITERATOR, iter, NULL);
00161 
00162     OCI_CHECK(iter->eoc == TRUE, NULL);
00163 
00164     iter->elem->init = FALSE;
00165 
00166     OCI_CALL2
00167     (
00168         res, iter->coll->con,
00169 
00170         OCIIterNext(OCILib.env, iter->coll->con->err, iter->handle,
00171                     &data, (dvoid **) &p_ind, &iter->eoc)
00172     )
00173 
00174     if ((res == TRUE) && (iter->eoc == FALSE))
00175     {
00176         elem = OCI_ElemInit(iter->coll->con, &iter->elem,
00177                             data, p_ind, iter->coll->typinf);
00178     }
00179 
00180     OCI_RESULT(elem != NULL);
00181 
00182     return elem;
00183 }
00184 
00185 /* --------------------------------------------------------------------------------------------- *
00186  * OCI_IterGetPrev
00187  * --------------------------------------------------------------------------------------------- */
00188 
00189 OCI_Elem * OCI_API OCI_IterGetPrev
00190 (
00191     OCI_Iter *iter
00192 )
00193 {
00194     boolean res    = TRUE;
00195     OCI_Elem *elem = NULL;
00196     void * data    = NULL;
00197     void *p_ind    = NULL;
00198 
00199     OCI_CHECK_PTR(OCI_IPC_ITERATOR, iter, NULL);
00200 
00201     OCI_CHECK(iter->boc == TRUE, NULL);
00202 
00203     iter->elem->init = FALSE;
00204 
00205     OCI_CALL2
00206     (
00207         res, iter->coll->con,
00208 
00209         OCIIterPrev(OCILib.env, iter->coll->con->err, iter->handle,
00210                     &data, (dvoid **) &p_ind, &iter->boc)
00211     )
00212 
00213     if ((res == TRUE) && (iter->boc == FALSE))
00214     {
00215         elem = OCI_ElemInit(iter->coll->con, &iter->elem,
00216                             data, p_ind, iter->coll->typinf);
00217     }
00218 
00219     OCI_RESULT(elem != NULL);
00220 
00221     return elem;
00222 
00223 }

Generated on Sun Oct 24 2010 22:02:54 for OCILIB (C Driver for Oracle) by  doxygen 1.7.1