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

D:/Perso/dev/ocilib/ocilib/src/statement.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: statement.c, v 3.8.1 2010-12-13 00:00 Vincent Rogier $
00033  * --------------------------------------------------------------------------------------------- */
00034 
00035 #include "ocilib_internal.h"
00036 
00037 /* ********************************************************************************************* *
00038  *                             PRIVATE FUNCTIONS
00039  * ********************************************************************************************* */
00040 
00041 /* --------------------------------------------------------------------------------------------- *
00042  * OCI_BindFreeAll
00043  * --------------------------------------------------------------------------------------------- */
00044 
00045 boolean OCI_BindFreeAll
00046 (
00047     OCI_Statement *stmt
00048 )
00049 {
00050     int i;
00051 
00052     OCI_CHECK(stmt == NULL, FALSE);
00053 
00054     /* free user binds */
00055 
00056     if (stmt->ubinds != NULL)
00057     {
00058         for(i = 0; i < stmt->nb_ubinds; i++)
00059         {
00060             OCI_BindFree(stmt->ubinds[i]);
00061         }
00062 
00063         OCI_FREE(stmt->ubinds);
00064     }
00065 
00066     /* free register binds */
00067 
00068     if (stmt->rbinds != NULL)
00069     {
00070         for(i = 0; i < stmt->nb_rbinds; i++)
00071         {
00072             OCI_BindFree(stmt->rbinds[i]);
00073         }
00074 
00075         OCI_FREE(stmt->rbinds);
00076     }
00077 
00078     stmt->nb_ubinds = 0;
00079     stmt->nb_rbinds = 0;
00080 
00081     return TRUE;
00082 }
00083 
00084 /* --------------------------------------------------------------------------------------------- *
00085  * OCI_BindCheck
00086  * --------------------------------------------------------------------------------------------- */
00087 
00088 boolean OCI_BindCheck
00089 (
00090     OCI_Statement *stmt
00091 )
00092 {
00093     boolean res   = TRUE;
00094     OCI_Bind *bnd = NULL;
00095     sb2 *ind      = NULL;
00096     ub4 i, j;
00097 
00098     OCI_CHECK(stmt == NULL, FALSE)
00099     OCI_CHECK(stmt->ubinds == NULL, TRUE);
00100 
00101     for(i = 0; i < stmt->nb_ubinds; i++)
00102     {
00103         bnd = stmt->ubinds[i];
00104         ind = (sb2 *) bnd->buf.inds;
00105 
00106         if (bnd->type == OCI_CDT_CURSOR)
00107         {
00108             OCI_Statement *bnd_stmt = (OCI_Statement *) bnd->buf.data;
00109 
00110             OCI_StatementReset(bnd_stmt);
00111         }
00112 
00113         /* for strings, re-initialize length array with buffer default size */
00114 
00115         if (bnd->type == OCI_CDT_TEXT)
00116         {
00117             unsigned int i;
00118 
00119             for (i=0; i < bnd->buf.count; i++)
00120             {
00121                 *(ub2*)(((ub1 *)bnd->buf.lens) + (sizeof(ub2) * (size_t) i)) = (ub2) bnd->size;
00122             }
00123         }
00124 
00125         /* extra work for internal allocated binds buffers */
00126 
00127         if (bnd->is_array == FALSE)
00128         {
00129             /* - For big integer (64 bits), we use an OCINumber.
00130 
00131                - Oracle date/time type is the only non scalar type
00132                  implemented by oracle through a public structure instead
00133                  of using a handle. So we need to copy the value
00134             */
00135 
00136             if ((bnd->type == OCI_CDT_NUMERIC) && (bnd->code == SQLT_VNU))
00137             {
00138                 res = OCI_NumberSet(stmt->con,
00139                                     (OCINumber *) bnd->buf.data,
00140                                     (void *) bnd->input,
00141                                     (uword) sizeof(big_int),
00142                                     bnd->subtype);
00143             }
00144             else if (bnd->alloc == TRUE)
00145             {
00146                 if (bnd->type == OCI_CDT_DATETIME)
00147                 {
00148                     if (bnd->input != NULL)
00149                     {
00150                         memcpy((void *) bnd->buf.data,
00151                                ((OCI_Date *) bnd->input)->handle, sizeof(OCIDate));
00152                     }
00153                 }
00154 
00155                 #ifdef OCI_CHECK_DATASTRINGS
00156 
00157                 else if (bnd->type == OCI_CDT_TEXT)
00158                 {
00159                     /* need conversion if bind buffer was allocated */
00160 
00161                     int osize = -1;
00162 
00163                     OCI_GetOutputString(bnd->input, bnd->buf.data, &osize,
00164                                         sizeof(dtext), sizeof(odtext));
00165                 }
00166 
00167                 #endif
00168 
00169                 else
00170                 {
00171                     if (bnd->input != NULL)
00172                     {
00173                         bnd->buf.data[0] = ((OCI_Datatype *) bnd->input)->handle;
00174                     }
00175                 }
00176             }
00177 
00178             /* for handles, check anyway the value for null data */
00179 
00180             if ((bnd->type != OCI_CDT_NUMERIC) &&
00181                 (bnd->type != OCI_CDT_TEXT   ) &&
00182                 (bnd->type != OCI_CDT_RAW    ))
00183             {
00184                 if (ind != NULL && *ind != -1)
00185                 {
00186                     *ind = OCI_IND(bnd->buf.data);
00187                 }
00188             }
00189 
00190             /* update bind object indicator pointer with object indicator */
00191 
00192             if (bnd->type == OCI_CDT_OBJECT)
00193             {
00194                 bnd->buf.obj_inds[0] = ((OCI_Object *) bnd->input)->tab_ind;
00195             }
00196 
00197             if (res == FALSE)
00198                 break;
00199         }
00200         else
00201         {
00202             for (j = 0; j < bnd->buf.count; j++, ind++)
00203             {
00204 
00205                 /* - For big integer (64 bits), we use an OCINumber.
00206 
00207                    - Oracle date/time type is the only non scalar type
00208                      implemented by oracle through a public structure instead
00209                      of using a handle. So we need to copy the value
00210                 */
00211 
00212                 if ((bnd->type == OCI_CDT_NUMERIC) && (bnd->code == SQLT_VNU))
00213                 {
00214 
00215                     res = OCI_NumberSet(stmt->con,
00216                                         (OCINumber *) ((ub1 *) bnd->buf.data +
00217                                                        (size_t) (j*bnd->size)),
00218                                         (void *) (((ub1 *) bnd->input) +
00219                                                   (((size_t)j)*sizeof(big_int))),
00220                                         (uword) sizeof(big_int), bnd->subtype);
00221                 }
00222                 else if (bnd->alloc == TRUE)
00223                 {
00224                     if (bnd->type == OCI_CDT_DATETIME)
00225                     {
00226                         if (bnd->input[j] != NULL)
00227                         {
00228                             memcpy(((ub1 *) bnd->buf.data) + (size_t) (j*bnd->size),
00229                                    ((OCI_Date *) bnd->input[j])->handle, sizeof(OCIDate));
00230                         }
00231                     }
00232 
00233                     #ifdef OCI_CHECK_DATASTRINGS
00234 
00235                     else if (bnd->type == OCI_CDT_TEXT)
00236                     {
00237                         /* need conversion if bind buffer was allocated */
00238 
00239                         int osize   = -1;
00240                         int offset1 = (bnd->size/sizeof(odtext))*sizeof(dtext);
00241                         int offset2 = bnd->size;
00242 
00243                         OCI_GetOutputString(((ub1 *) bnd->input)    + (j*offset1),
00244                                             ((ub1 *) bnd->buf.data) + (j*offset2),
00245                                             &osize, sizeof(dtext), sizeof(odtext));
00246 
00247                         /* set zero terminal null character */
00248 
00249                         {
00250                             odtext *str = (odtext *) (((ub1 *) bnd->buf.data) + (j*offset2));
00251 
00252                             if (osize> 0)
00253                                 str[osize/sizeof(odtext)] = 0;
00254                             else
00255                                 str[0] = 0;
00256                         }
00257                     }
00258 
00259                     #endif
00260 
00261                     else
00262                     {
00263                         if (bnd->input[j] != NULL)
00264                         {
00265                             bnd->buf.data[j] = ((OCI_Datatype *) bnd->input[j])->handle;
00266                         }
00267                     }
00268                 }
00269 
00270                 /* for handles, check anyway the value for null data */
00271 
00272                 if ((bnd->type != OCI_CDT_NUMERIC) &&
00273                     (bnd->type != OCI_CDT_TEXT   ) &&
00274                     (bnd->type != OCI_CDT_RAW    ))
00275                 {
00276                     if (ind != NULL && *ind != -1)
00277                     {
00278                         *ind = OCI_IND((((OCI_Datatype *) bnd->input[j])->handle));
00279                     }
00280                 }
00281 
00282                 /* update bind object indicator pointer with object indicator */
00283 
00284                 if (bnd->type == OCI_CDT_OBJECT)
00285                 {
00286                     bnd->buf.obj_inds[j] = ((OCI_Object *) bnd->input[j])->tab_ind;
00287                 }
00288 
00289                 if (res == FALSE)
00290                     break;
00291             }
00292         }
00293     }
00294 
00295     return res;
00296 }
00297 
00298 /* --------------------------------------------------------------------------------------------- *
00299  * OCI_BindReset
00300  * --------------------------------------------------------------------------------------------- */
00301 
00302 boolean OCI_BindReset
00303 (
00304     OCI_Statement *stmt
00305 )
00306 {
00307     ub4 i, j;
00308     boolean res = TRUE;
00309 
00310     OCI_CHECK(stmt == NULL, FALSE)
00311     OCI_CHECK(stmt->ubinds == NULL, FALSE);
00312 
00313     /* avoid unused param warning from compiler */
00314 
00315     i = j = 0;
00316 
00317     for(i = 0; i < stmt->nb_ubinds; i++)
00318     {
00319         OCI_Bind *bnd = stmt->ubinds[i];
00320 
00321         if (bnd->type == OCI_CDT_CURSOR)
00322         {
00323             OCI_Statement *bnd_stmt = (OCI_Statement *) bnd->buf.data;
00324 
00325             bnd_stmt->status = OCI_STMT_EXECUTED;
00326             bnd_stmt->type   = OCI_CST_SELECT;
00327         }
00328 
00329         /* only reset bind indicators if bind was not a PL/SQL bind
00330            that can have oupout values
00331         */
00332 
00333         if (stmt->type != OCI_CST_BEGIN && stmt->type != OCI_CST_DECLARE)
00334         {
00335             memset(bnd->buf.inds, 0, ((size_t) bnd->buf.count) * sizeof(sb2));
00336         }
00337         else
00338         {
00339             /* extra work for internal allocated binds buffers with PL/SQL */
00340 
00341             if (bnd->is_array == FALSE)
00342             {
00343                 /* - For big integer (64 bits), we use an OCINumber.
00344 
00345                    - Oracle date/time type is the only non scalar type
00346                      implemented by oracle through a public structure instead
00347                      of using a handle. So we need to copy the value
00348                 */
00349 
00350                 if ((bnd->type == OCI_CDT_NUMERIC) && (bnd->code == SQLT_VNU))
00351                 {
00352                     res = OCI_NumberGet(stmt->con,
00353                                         (OCINumber *) bnd->buf.data,
00354                                         (void *) bnd->input,
00355                                         (uword) sizeof(big_int),
00356                                         bnd->subtype);
00357                 }
00358                 else if (bnd->alloc == TRUE)
00359                 {
00360 
00361                     if (bnd->type == OCI_CDT_DATETIME)
00362                     {
00363                         if (bnd->input != NULL)
00364                         {
00365                             memcpy(((OCI_Date *) bnd->input)->handle,
00366                                    (void *) bnd->buf.data, sizeof(OCIDate));
00367                         }
00368                     }
00369 
00370                     /* update object indicator with bind object indicator
00371                      *pointer */
00372 
00373                     if (bnd->type == OCI_CDT_OBJECT)
00374                     {
00375                         if (bnd->input != NULL)
00376                         {
00377                             ((OCI_Object *) bnd->input)->tab_ind = bnd->buf.obj_inds[0];
00378                         }
00379                     }
00380                 }
00381             }
00382             else
00383             {
00384                 for (j = 0; j < bnd->buf.count; j++)
00385                 {
00386 
00387                     /* - For big integer (64 bits), we use an OCINumber.
00388 
00389                        - Oracle date/time type is the only non scalar type
00390                          implemented by oracle through a public structure instead
00391                          of using a handle. So we need to copy the value
00392                     */
00393 
00394                     if ((bnd->type == OCI_CDT_NUMERIC) && (bnd->code == SQLT_VNU))
00395                     {
00396 
00397                         res = OCI_NumberGet(stmt->con,
00398                                             (OCINumber *) ((ub1 *) bnd->buf.data +
00399                                                            (size_t) (j*bnd->size)),
00400                                             (void *) (((ub1 *) bnd->input) +
00401                                                       (((size_t)j)*sizeof(big_int))),
00402                                             (uword) sizeof(big_int), bnd->subtype);
00403                     }
00404                     else if (bnd->alloc == TRUE)
00405                     {
00406                         if (bnd->type == OCI_CDT_DATETIME)
00407                         {
00408                             if (bnd->input[j] != NULL)
00409                             {
00410                                 memcpy(((OCI_Date *) bnd->input[j])->handle,
00411                                        ((ub1 *) bnd->buf.data) + (size_t) (j*bnd->size),
00412                                        sizeof(OCIDate));
00413                             }
00414                         }
00415 
00416                         /* update bind object indicator pointer with object
00417                          *indicator */
00418 
00419                         if (bnd->type == OCI_CDT_OBJECT)
00420                         {
00421                             if (bnd->input != NULL)
00422                             {
00423                                 ((OCI_Object *) bnd->input[j])->tab_ind = bnd->buf.obj_inds[j];
00424                             }
00425                         }
00426                     }
00427                 }
00428             }
00429         }
00430 
00431         #ifdef OCI_CHECK_DATASTRINGS
00432 
00433         if (bnd->type == OCI_CDT_TEXT)
00434         {
00435             for (j = 0; j < bnd->buf.count; j++)
00436             {
00437                 /* need conversion if bind buffer was allocated */
00438 
00439                 int osize   = -1;
00440                 int offset1 = (bnd->size/sizeof(odtext))*sizeof(dtext);
00441                 int offset2 = bnd->size;
00442 
00443                 if (bnd->buf.lens != NULL)
00444                     osize = (int) ((ub2 *) bnd->buf.lens)[j];
00445 
00446                 if (bnd->size == (sb4) osize)
00447                     osize -= sizeof(odtext);
00448 
00449                 OCI_GetOutputString(((ub1 *) bnd->buf.data) + (j*offset2),
00450                                     ((ub1 *) bnd->input)    + (j*offset1),
00451                                     &osize, sizeof(odtext), sizeof(dtext));
00452 
00453                 /* set zero terminal null character (sometimes it is not set
00454                    by OCI and causes problems if the string has been modified
00455                    and its length reduced */
00456 
00457                 {
00458                     dtext *str = (dtext *) (((ub1 *) bnd->input) + (j*offset1));
00459 
00460                     if (osize> 0)
00461                         str[osize/sizeof(dtext)] = 0;
00462                 }
00463             }
00464         }
00465         #endif
00466 
00467     }
00468 
00469     return res;
00470 }
00471 
00472 /* --------------------------------------------------------------------------------------------- *
00473  * OCI_BindData
00474  * --------------------------------------------------------------------------------------------- */
00475 
00476 boolean OCI_BindData
00477 (
00478     OCI_Statement *stmt,
00479     void          *data,
00480     ub4            size,
00481     const mtext   *name,
00482     ub1            type,
00483     unsigned int   code,
00484     unsigned int   mode,
00485     unsigned int   subtype,
00486     OCI_TypeInfo  *typinf,
00487     unsigned int   nbelem
00488 )
00489 {
00490     boolean res      = TRUE;
00491     OCI_Bind *bnd    = NULL;
00492     ub4 exec_mode    = OCI_DEFAULT;
00493     boolean is_pltbl = FALSE;
00494     boolean is_array = FALSE;
00495     boolean reused   = FALSE;
00496     ub4 *pnbelem     = NULL;
00497     int index        = 0;
00498     int prev_index   = -1;
00499     size_t nballoc   = (size_t) nbelem;
00500 
00501     /* check index if necessary */
00502 
00503     if (res == TRUE)
00504     {
00505         if (stmt->bind_mode == OCI_BIND_BY_POS)
00506         {
00507             index = (int) mtstol(&name[1], NULL, 10);
00508 
00509             if (index <= 0 || index > OCI_BIND_MAX)
00510             {
00511                 OCI_ExceptionOutOfBounds(stmt->con, index);
00512                 res = FALSE;
00513             }
00514         }
00515     }
00516 
00517     /* check if the bind name has already been used */
00518 
00519     if (res == TRUE)
00520     {
00521         if (mode == OCI_BIND_INPUT)
00522         {
00523             prev_index = OCI_BindGetIndex(stmt, name);
00524 
00525             if (prev_index > 0)
00526             {
00527                 if (stmt->bind_reuse == FALSE)
00528                 {
00529                     OCI_ExceptionBindAlreadyUsed(stmt, name);
00530                     res = FALSE;
00531                 }
00532                 else
00533                 {
00534                     bnd = stmt->ubinds[prev_index-1];
00535 
00536                     if (bnd->type != type)
00537                     {
00538                         OCI_ExceptionRebindBadDatatype(stmt, name);
00539                         res = FALSE;
00540                     }
00541                     else
00542                         reused = TRUE;
00543                 }
00544 
00545                 index = prev_index;
00546             }
00547         }
00548     }
00549 
00550     /* check if we can handle another bind */
00551 
00552     if (res == TRUE)
00553     {
00554         if (mode == OCI_BIND_INPUT)
00555         {
00556             if (stmt->nb_ubinds >= OCI_BIND_MAX)
00557             {
00558                 OCI_ExceptionMaxBind(stmt);
00559                 res = FALSE;
00560             }
00561 
00562             /* allocate user bind array if necessary */
00563 
00564             if (stmt->ubinds == NULL)
00565             {
00566                 stmt->ubinds = (OCI_Bind **) OCI_MemAlloc(OCI_IPC_BIND_ARRAY,
00567                                                           sizeof(*stmt->ubinds),
00568                                                           (size_t) OCI_BIND_MAX,
00569                                                           TRUE);
00570             }
00571 
00572             res = (stmt->ubinds != NULL);
00573         }
00574         else
00575         {
00576             if (stmt->nb_rbinds >= OCI_BIND_MAX)
00577             {
00578                 OCI_ExceptionMaxBind(stmt);
00579                 res = FALSE;
00580             }
00581 
00582             /* allocate register bind array if necessary */
00583 
00584             if (stmt->rbinds == NULL)
00585             {
00586                 stmt->rbinds = (OCI_Bind **) OCI_MemAlloc(OCI_IPC_BIND_ARRAY,
00587                                                           sizeof(*stmt->rbinds),
00588                                                           (size_t) OCI_BIND_MAX,
00589                                                           TRUE);
00590             }
00591 
00592             res = (stmt->rbinds != NULL);
00593         }
00594     }
00595 
00596     /* checks done */
00597 
00598     if (res == TRUE)
00599     {
00600         /* check out the number of elements that the bind variable will hold */
00601 
00602         if (nbelem > 0)
00603         {
00604             /* is it a pl/sql table bind ? */
00605 
00606             if (stmt->type == OCI_CST_BEGIN || stmt->type == OCI_CST_DECLARE)
00607             {
00608                 is_pltbl = TRUE;
00609                 is_array = TRUE;
00610             }
00611         }
00612         else
00613         {
00614             nbelem   = stmt->nb_iters;
00615             is_array = stmt->bind_array;
00616         }
00617     }
00618 
00619     if (res == TRUE)
00620     {
00621         if (nballoc < stmt->nb_iters_init)
00622         {
00623             nballoc = (size_t) stmt->nb_iters_init;
00624         }
00625     }
00626 
00627     /* create hash table for mapping bind names / index */
00628 
00629     if (res == TRUE)
00630     {
00631         if (stmt->map == NULL)
00632         {
00633             stmt->map = OCI_HashCreate(OCI_HASH_DEFAULT_SIZE, OCI_HASH_INTEGER);
00634 
00635             res = (stmt->map != NULL);
00636         }
00637     }
00638 
00639     /* allocate bind object */
00640 
00641     if (res == TRUE)
00642     {
00643         if (bnd == NULL)
00644         {
00645             bnd = (OCI_Bind *) OCI_MemAlloc(OCI_IPC_BIND, sizeof(*bnd),
00646                                             (size_t) 1, TRUE);
00647         }
00648 
00649         res = (bnd != NULL);
00650     }
00651 
00652     /* allocate indicators array */
00653 
00654     if (res == TRUE)
00655     {
00656         if (bnd->buf.inds == NULL)
00657         {
00658             bnd->buf.inds = (void *) OCI_MemAlloc(OCI_IPC_INDICATOR_ARRAY,
00659                                                   sizeof(sb2), nballoc,
00660                                                   TRUE);
00661         }
00662 
00663         res = (bnd->buf.inds != NULL);
00664     }
00665 
00666     /* allocate object indicators pointer array */
00667 
00668     if (res == TRUE)
00669     {
00670         if ((type == OCI_CDT_OBJECT) && (bnd->buf.obj_inds == NULL))
00671         {
00672             bnd->buf.obj_inds = (void *) OCI_MemAlloc(OCI_IPC_INDICATOR_ARRAY,
00673                                                       sizeof(void *), nballoc,
00674                                                       TRUE);
00675 
00676             res = (bnd->buf.obj_inds != NULL);
00677         }
00678     }
00679 
00680     /* check need for PL/SQL table extra info */
00681 
00682     if ((res == TRUE) && (is_pltbl == TRUE))
00683     {
00684         bnd->nbelem = nbelem;
00685         pnbelem     = &bnd->nbelem;
00686 
00687         /* allocate array of returned codes */
00688 
00689         if (res == TRUE)
00690         {
00691             if (bnd->plrcds == NULL)
00692             {
00693                 bnd->plrcds = (ub2 *) OCI_MemAlloc(OCI_IPC_PLS_RCODE_ARRAY,
00694                                                    sizeof(ub2), nballoc,
00695                                                    TRUE);
00696             }
00697 
00698             res = (bnd->plrcds != NULL);
00699         }
00700     }
00701 
00702     /* for handle based datatypes, we need to allocate an array of handles for
00703        bind calls because OCILIB uses external arrays of OCILIB Objects */
00704 
00705     if ((res == TRUE) && (mode == OCI_BIND_INPUT))
00706     {
00707         if (stmt->bind_alloc_mode == OCI_BAM_EXTERNAL)
00708         {
00709             if (type != OCI_CDT_RAW      &&
00710                 type != OCI_CDT_LONG     &&
00711                 type != OCI_CDT_CURSOR   &&
00712 
00713                 #ifndef OCI_CHECK_DATASTRINGS
00714 
00715                 type != OCI_CDT_TEXT     &&
00716 
00717                 #endif
00718                 (type != OCI_CDT_NUMERIC || code == SQLT_VNU)
00719                 )
00720             {
00721                 bnd->alloc = TRUE;
00722 
00723                 if ((reused == TRUE) && (bnd->buf.data != NULL) && (bnd->size != (sb4) size))
00724                 {
00725                     OCI_FREE(bnd->buf.data);
00726                 }
00727 
00728                 if (bnd->buf.data == NULL)
00729                 {
00730                     bnd->buf.data = (void **) OCI_MemAlloc(OCI_IPC_BUFF_ARRAY,
00731                                                            (size_t) size,
00732                                                            (size_t) nballoc,
00733                                                            TRUE);
00734                 }
00735 
00736                 res = (bnd->buf.data != NULL);
00737             }
00738             else
00739                 bnd->buf.data = (void **) data;
00740         }
00741     }
00742 
00743     /* setup data length array */
00744 
00745     if ((res == TRUE) && ((type == OCI_CDT_RAW) || (type == OCI_CDT_TEXT)))
00746     {
00747         if (bnd->buf.lens == NULL)
00748         {
00749             bnd->buf.lens = (void *) OCI_MemAlloc(OCI_IPC_LEN_ARRAY, sizeof(ub2),
00750                                                   nballoc, TRUE);
00751         }
00752 
00753         res = (bnd->buf.lens != NULL);
00754 
00755         /* initialize length array with buffer default size */
00756 
00757         if (res == TRUE)
00758         {
00759             unsigned int i;
00760 
00761             for (i=0; i < nbelem; i++)
00762             {
00763                 *(ub2*)(((ub1 *)bnd->buf.lens) + sizeof(ub2) * (size_t) i) = (ub2) size;
00764             }
00765         }
00766     }
00767 
00768     /* initialize bind object */
00769 
00770     if (res == TRUE)
00771     {
00772         /* initialize bind attributes */
00773 
00774         bnd->stmt     = stmt;
00775         bnd->input    = (void **) data;
00776         bnd->type     = type;
00777         bnd->size     = size;
00778         bnd->code     = (ub2) code;
00779         bnd->subtype  = (ub1) subtype;
00780         bnd->is_array = is_array;
00781         bnd->csfrm    = OCI_CSF_NONE;
00782 
00783         if (bnd->name == NULL)
00784         {
00785             bnd->name = mtsdup(name);
00786         }
00787 
00788         /* initialize buffer */
00789 
00790         bnd->buf.count   = nbelem;
00791         bnd->buf.sizelen = sizeof(ub2);
00792 
00793         /* internal allocation if needed */
00794 
00795         if ((data == NULL) && (stmt->bind_alloc_mode == OCI_BAM_INTERNAL))
00796         {
00797             res = OCI_BindAllocData(bnd);
00798         }
00799 
00800         /* if we bind an OCI_Long or any output bind, we need to change the
00801            execution mode to provide data at execute time */
00802 
00803         if (bnd->type == OCI_CDT_LONG)
00804         {
00805             stmt->long_size = size;
00806             exec_mode       = OCI_DATA_AT_EXEC;
00807         }
00808         else if (mode == OCI_BIND_OUTPUT)
00809         {
00810             exec_mode = OCI_DATA_AT_EXEC;
00811         }
00812     }
00813 
00814     /* OCI binding */
00815 
00816     if (res == TRUE)
00817     {
00818         if (stmt->bind_mode == OCI_BIND_BY_POS)
00819         {
00820             OCI_CALL1
00821             (
00822                 res, stmt->con, stmt,
00823 
00824                 OCIBindByPos(stmt->stmt, (OCIBind **) &bnd->buf.handle,
00825                              stmt->con->err, (ub4) index, (void *) bnd->buf.data,
00826                              bnd->size, bnd->code, bnd->buf.inds,  bnd->buf.lens,
00827                              bnd->plrcds, (ub4) (is_pltbl == TRUE ? nbelem : 0),
00828                              pnbelem, exec_mode)
00829             )
00830         }
00831         else
00832         {
00833             void * ostr = NULL;
00834             int osize   = -1;
00835 
00836             ostr = OCI_GetInputMetaString(bnd->name, &osize);
00837 
00838             OCI_CALL1
00839             (
00840                 res, stmt->con, stmt,
00841 
00842                 OCIBindByName(stmt->stmt, (OCIBind **) &bnd->buf.handle,
00843                               stmt->con->err, (OraText *) ostr, (sb4) osize,
00844                               (void *) bnd->buf.data, bnd->size, bnd->code,
00845                               bnd->buf.inds, bnd->buf.lens, bnd->plrcds,
00846                               (ub4) (is_pltbl == TRUE ? nbelem : 0),
00847                               pnbelem, exec_mode)
00848             )
00849 
00850             OCI_ReleaseMetaString(ostr);
00851         }
00852 
00853         if (code == SQLT_NTY || code == SQLT_REF)
00854         {
00855             OCI_CALL1
00856             (
00857                 res, stmt->con, stmt,
00858 
00859                 OCIBindObject((OCIBind *) bnd->buf.handle, stmt->con->err,
00860                               (OCIType *) typinf->tdo, (void **) bnd->buf.data,
00861                               (ub4 *) NULL, (void **) bnd->buf.obj_inds,
00862                               (ub4 *) bnd->buf.inds)
00863             )
00864         }
00865 
00866         if (mode == OCI_BIND_OUTPUT)
00867         {
00868             /* register output placeholder */
00869 
00870             OCI_CALL1
00871             (
00872                 res, stmt->con, stmt,
00873 
00874                 OCIBindDynamic((OCIBind *) bnd->buf.handle, stmt->con->err,
00875                                (dvoid *) bnd, OCI_ProcInBind,
00876                                (dvoid *) bnd, OCI_ProcOutBind)
00877             )
00878         }
00879     }
00880 
00881     /* set charset form */
00882 
00883     if (res == TRUE)
00884     {
00885         if ((bnd->type == OCI_CDT_LOB) && (bnd->subtype == OCI_NCLOB))
00886         {
00887             ub1 csfrm = SQLCS_NCHAR;
00888 
00889             OCI_CALL1
00890             (
00891                 res, bnd->stmt->con, bnd->stmt,
00892 
00893                 OCIAttrSet((dvoid *) bnd->buf.handle,
00894                            (ub4    ) OCI_HTYPE_BIND,
00895                            (dvoid *) &csfrm,
00896                            (ub4    ) sizeof(csfrm),
00897                            (ub4    ) OCI_ATTR_CHARSET_FORM,
00898                            bnd->stmt->con->err)
00899             )
00900         }
00901     }
00902 
00903     /* set charset ID */
00904 
00905     if (res == TRUE)
00906     {
00907         if ((bnd->type == OCI_CDT_TEXT)  ||
00908             ((bnd->type == OCI_CDT_LOB)   && (bnd->subtype != OCI_BLOB))  ||
00909             ((bnd->type == OCI_CDT_LONG)  && (bnd->subtype != OCI_BLONG)))
00910         {
00911 
00912             #ifdef OCI_CHARSET_MIXED
00913 
00914             /* setup Unicode mode for user data on mixed builds */
00915             {
00916                 ub2 csid = OCI_UTF16ID;
00917 
00918                 OCI_CALL1
00919                 (
00920                     res, bnd->stmt->con, bnd->stmt,
00921 
00922                     OCIAttrSet((dvoid *) bnd->buf.handle,
00923                                (ub4    ) OCI_HTYPE_BIND,
00924                                (dvoid *) &csid,
00925                                (ub4    ) sizeof(csid),
00926                                (ub4    ) OCI_ATTR_CHARSET_ID,
00927                                bnd->stmt->con->err)
00928                 )
00929             }
00930 
00931             #endif
00932 
00933         }
00934     }
00935 
00936 /*
00937     this call was removed in v3.6.0
00938 
00939     It will be restored in future version, but need more testing on all
00940     builds
00941     if (bnd->type == OCI_CDT_TEXT)
00942     {
00943         OCI_CALL1
00944         (
00945             res, stmt->con, stmt,
00946 
00947             OCIAttrSet((dvoid *) bnd->buf.handle, (ub4) OCI_HTYPE_BIND,
00948                        (dvoid *) &bnd->size, (ub4) sizeof(bnd->size),
00949                        (ub4) OCI_ATTR_MAXDATA_SIZE,  bnd->stmt->con->err)
00950         )
00951     }
00952 */
00953 
00954     /* on success, we :
00955          - add the bind handle to the bind array
00956          - add the bind index to the map
00957     */
00958 
00959     if (res == TRUE)
00960     {
00961         if (mode == OCI_BIND_INPUT)
00962         {
00963             if (reused == FALSE)
00964             {
00965                 stmt->ubinds[stmt->nb_ubinds++] = bnd;
00966 
00967                 /* for user binds, add a positive index */
00968 
00969                 OCI_HashAddInt(stmt->map, name, stmt->nb_ubinds);
00970             }
00971         }
00972         else
00973         {
00974             /* for register binds, add a negative index */
00975 
00976             stmt->rbinds[stmt->nb_rbinds++] = bnd;
00977 
00978             index = (int) stmt->nb_rbinds;
00979 
00980             OCI_HashAddInt(stmt->map, name, -index);
00981         }
00982     }
00983 
00984     if (res == FALSE)
00985     {
00986         if ((bnd != NULL) && (prev_index  == -1))
00987         {
00988             OCI_BindFree(bnd);
00989         }
00990     }
00991 
00992     OCI_RESULT(res);
00993 
00994     return res;
00995 }
00996 
00997 /* --------------------------------------------------------------------------------------------- *
00998  * OCI_BindGetIndex
00999  * --------------------------------------------------------------------------------------------- */
01000 
01001 int OCI_BindGetIndex
01002 (
01003     OCI_Statement *stmt,
01004     const mtext   *name
01005 )
01006 {
01007     OCI_HashEntry *he = NULL;
01008     int index         = -1;
01009 
01010     OCI_CHECK_PTR(OCI_IPC_STATEMENT, stmt, -1);
01011     OCI_CHECK_PTR(OCI_IPC_STRING, name, -1);
01012 
01013     if (stmt->map != NULL)
01014     {
01015         he = OCI_HashLookup(stmt->map, name, FALSE);
01016 
01017         while (he != NULL)
01018         {
01019             /* no more entries or key matched => so we got it ! */
01020 
01021             if (he->next == NULL || mtscasecmp(he->key, name) == 0)
01022             {
01023                 /* in order to sue the same map for user binds and
01024                    register binds :
01025                       - user binds are stored as positive values
01026                       - registers binds are stored as negatives values
01027                 */
01028 
01029                 index = he->values->value.num;
01030 
01031                 if (index < 0)
01032                     index = -index;
01033 
01034                 break;
01035             }
01036         }
01037     }
01038 
01039     return index;
01040 }
01041 
01042 /* --------------------------------------------------------------------------------------------- *
01043  * OCI_FetchIntoUserVariables
01044  * --------------------------------------------------------------------------------------------- */
01045 
01046 boolean OCI_FetchIntoUserVariables
01047 (
01048     OCI_Statement *stmt,
01049     va_list        args
01050 )
01051 {
01052     OCI_Resultset *rs = NULL;
01053     boolean res       = FALSE;
01054     int i, n;
01055 
01056     /* get resultset */
01057 
01058     rs = OCI_GetResultset(stmt);
01059 
01060     /* fetch data */
01061 
01062     if (rs != NULL)
01063         res = OCI_FetchNext(rs);
01064 
01065     if (res == TRUE)
01066     {
01067         /* loop on column list for updating user given placeholders */
01068 
01069         for (i = 1, n = OCI_GetColumnCount(rs); i <= n && res == TRUE; i++)
01070         {
01071             OCI_Column *col = OCI_GetColumn(rs, i);
01072 
01073             int type = va_arg(args, int);
01074 
01075             switch (type)
01076             {
01077                 case OCI_ARG_SHORT:
01078                 {
01079                     short src, *dst;
01080 
01081                     src = OCI_GetShort(rs, i);
01082                     dst = va_arg(args, short *);
01083 
01084                     if (dst != NULL)
01085                         *dst = src;
01086 
01087                     break;
01088                 }
01089                 case OCI_ARG_USHORT:
01090                 {
01091                     unsigned short src, *dst;
01092 
01093                     src = OCI_GetUnsignedShort(rs, i);
01094                     dst = va_arg(args, unsigned short *);
01095 
01096                     if (dst != NULL)
01097                         *dst = src;
01098 
01099                     break;
01100                 }
01101                 case OCI_ARG_INT:
01102                 {
01103                     int src, *dst;
01104 
01105                     src = OCI_GetInt(rs, i);
01106                     dst = va_arg(args, int *);
01107 
01108                     if (dst != NULL)
01109                         *dst = src;
01110 
01111                     break;
01112                 }
01113                 case OCI_ARG_UINT:
01114                 {
01115                     unsigned int src, *dst;
01116 
01117                     src = OCI_GetUnsignedInt(rs, i);
01118                     dst = va_arg(args, unsigned int *);
01119 
01120                     if (dst != NULL)
01121                         *dst = src;
01122 
01123                     break;
01124                 }
01125                 case OCI_ARG_BIGINT:
01126                 {
01127                     big_int src, *dst;
01128 
01129                     src = OCI_GetBigInt(rs, i);
01130                     dst = va_arg(args, big_int *);
01131 
01132                     if (dst != NULL)
01133                         *dst = src;
01134 
01135                     break;
01136                 }
01137                 case OCI_ARG_BIGUINT:
01138                 {
01139                     big_uint src, *dst;
01140 
01141                     src = OCI_GetUnsignedBigInt(rs, i);
01142                     dst = va_arg(args, big_uint *);
01143 
01144                     if (dst != NULL)
01145                         *dst = src;
01146 
01147                     break;
01148                 }
01149                 case OCI_ARG_DOUBLE:
01150                 {
01151                     double src, *dst;
01152 
01153                     src = OCI_GetDouble(rs, i);
01154                     dst = va_arg(args, double *);
01155 
01156                     if (dst != NULL)
01157                         *dst = src;
01158 
01159                     break;
01160                 }
01161                 case OCI_ARG_DATETIME:
01162                 {
01163                     OCI_Date *src, *dst;
01164 
01165                     src = OCI_GetDate(rs, i);
01166                     dst = (OCI_Date *) va_arg(args, OCI_Date *);
01167 
01168                     if (src != NULL && dst != NULL)
01169                         res = OCI_DateAssign(dst, src);
01170 
01171                     break;
01172                 }
01173                 case OCI_ARG_TEXT:
01174                 {
01175                     const dtext *src;
01176                     dtext *dst;
01177 
01178                     src = OCI_GetString(rs, i);
01179                     dst = va_arg(args, dtext *);
01180 
01181                     if (dst != NULL)
01182                         dst[0] = 0;
01183 
01184                     if (dst != NULL && src != NULL)
01185                         dtscat(dst, src);
01186 
01187                     break;
01188                 }
01189                 case OCI_ARG_RAW:
01190                 {
01191                     OCI_GetRaw(rs, i, va_arg(args, dtext *), col->bufsize);
01192                     break;
01193                 }
01194                 case OCI_ARG_LOB:
01195                 {
01196                     OCI_Lob *src, *dst;
01197 
01198                     src = OCI_GetLob(rs, i);
01199                     dst = (OCI_Lob *) va_arg(args, OCI_Lob *);
01200 
01201                     if (src != NULL && dst != NULL)
01202                         res = OCI_LobAssign(dst, src);
01203 
01204                     break;
01205                 }
01206                 case OCI_ARG_FILE:
01207                 {
01208                     OCI_File *src, *dst;
01209 
01210                     src = OCI_GetFile(rs, i);
01211                     dst = (OCI_File *) va_arg(args, OCI_File *);
01212 
01213                     if (src != NULL && dst != NULL)
01214                         res = OCI_FileAssign(dst, src);
01215 
01216                     break;
01217                 }
01218                 case OCI_ARG_TIMESTAMP:
01219                 {
01220                     OCI_Timestamp *src, *dst;
01221 
01222                     src = OCI_GetTimestamp(rs, i);
01223                     dst = (OCI_Timestamp *) va_arg(args, OCI_Timestamp *);
01224 
01225                     if (src != NULL && dst != NULL)
01226                         res = OCI_TimestampAssign(dst, src);
01227 
01228                     break;
01229                 }
01230                 case OCI_ARG_INTERVAL:
01231                 {
01232                     OCI_Interval *src, *dst;
01233 
01234                     src = OCI_GetInterval(rs, i);
01235                     dst = (OCI_Interval *) va_arg(args, OCI_Interval *);
01236 
01237                     if (src != NULL && dst != NULL)
01238                         res =OCI_IntervalAssign(dst, src);
01239 
01240                     break;
01241                 }
01242                 case OCI_ARG_OBJECT:
01243                 {
01244                     OCI_Object *src, *dst;
01245 
01246                     src = OCI_GetObject(rs, i);
01247                     dst = (OCI_Object *) va_arg(args, OCI_Object *);
01248 
01249                     if (src != NULL && dst != NULL)
01250                         res =OCI_ObjectAssign(dst, src);
01251 
01252                     break;
01253                 }
01254                 case OCI_ARG_COLLECTION:
01255                 {
01256                     OCI_Coll *src, *dst;
01257 
01258                     src = OCI_GetColl(rs, i);
01259                     dst = (OCI_Coll *) va_arg(args, OCI_Coll *);
01260 
01261                     if (src != NULL && dst != NULL)
01262                         res =OCI_CollAssign(dst, src);
01263 
01264                     break;
01265                 }
01266                 case OCI_ARG_REF:
01267                 {
01268                     OCI_Ref *src, *dst;
01269 
01270                     src = OCI_GetRef(rs, i);
01271                     dst = (OCI_Ref *) va_arg(args, OCI_Ref *);
01272 
01273                     if (src != NULL && dst != NULL)
01274                         res =OCI_RefAssign(dst, src);
01275 
01276                     break;
01277                 }
01278                 default:
01279                 {
01280                     OCI_ExceptionMappingArgument(stmt->con, stmt, type);
01281 
01282                     res = FALSE;
01283 
01284                     break;
01285                 }
01286             }
01287         }
01288     }
01289 
01290     return res;
01291 }
01292 
01293 /* --------------------------------------------------------------------------------------------- *
01294  * OCI_StatementInit
01295  * --------------------------------------------------------------------------------------------- */
01296 
01297 OCI_Statement * OCI_StatementInit
01298 (
01299     OCI_Connection *con,
01300     OCI_Statement **pstmt,
01301     OCIStmt        *handle,
01302     OCI_Define     *def
01303 )
01304 {
01305     OCI_Statement * stmt = NULL;
01306     boolean res          = TRUE;
01307 
01308     OCI_CHECK(pstmt == NULL, NULL);
01309 
01310     if (*pstmt == NULL)
01311         *pstmt = (OCI_Statement *) OCI_MemAlloc(OCI_IPC_STATEMENT, sizeof(*stmt),
01312                                                 (size_t) 1, TRUE);
01313 
01314     if (*pstmt != NULL)
01315     {
01316         stmt = *pstmt;
01317 
01318         stmt->con  = con;
01319         stmt->stmt = handle;
01320 
01321         stmt->exec_mode       = OCI_DEFAULT;
01322         stmt->long_size       = OCI_SIZE_LONG;
01323         stmt->bind_reuse      = FALSE;
01324         stmt->bind_mode       = OCI_BIND_BY_NAME;
01325         stmt->long_mode       = OCI_LONG_EXPLICIT;
01326         stmt->bind_alloc_mode = OCI_BAM_EXTERNAL;
01327 
01328         /* reset statement */
01329 
01330         OCI_StatementReset(stmt);
01331 
01332         if (def == NULL)
01333         {
01334             /* allocate handle for non fetched cursor */
01335 
01336             stmt->hstate = OCI_OBJECT_ALLOCATED;
01337 
01338             /* allocate handle */
01339 
01340             res = (OCI_SUCCESS == OCI_HandleAlloc((dvoid *) OCILib.env,
01341                                                   (dvoid **) (void *) &stmt->stmt,
01342                                                   (ub4) OCI_HTYPE_STMT,
01343                                                   (size_t) 0, (dvoid **) NULL));
01344         }
01345         else
01346         {
01347             stmt->hstate = OCI_OBJECT_FETCHED_CLEAN;
01348             stmt->status = OCI_STMT_EXECUTED;
01349             stmt->type   = OCI_CST_SELECT;
01350 
01351             /* not really perfect, but better than nothing */
01352 
01353             if (def->col.name != NULL)
01354                 stmt->sql = mtsdup(def->col.name);
01355         }
01356 
01357         /* set statement default attributes */
01358 
01359         OCI_SetPrefetchSize(stmt, OCI_PREFETCH_SIZE);
01360         OCI_SetFetchSize(stmt, OCI_FETCH_SIZE);
01361     }
01362 
01363     /* check for failure */
01364 
01365     if (res == FALSE)
01366     {
01367         OCI_StatementFree(stmt);
01368         stmt = NULL;
01369     }
01370 
01371     return stmt;
01372 }
01373 
01374 /* --------------------------------------------------------------------------------------------- *
01375  * OCI_StatementReset
01376  * --------------------------------------------------------------------------------------------- */
01377 
01378 boolean OCI_StatementReset
01379 (
01380     OCI_Statement *stmt
01381 )
01382 {
01383     boolean res = TRUE;
01384 
01385     /* reset batch errors */
01386 
01387     res = OCI_BatchErrorClear(stmt);
01388 
01389     /* free resultsets */
01390 
01391     res = OCI_ReleaseResultsets(stmt);
01392 
01393     /* free in/out binds */
01394 
01395     res = OCI_BindFreeAll(stmt);
01396 
01397     /* free bind map */
01398 
01399     if (stmt->map != NULL)
01400     {
01401         OCI_HashFree(stmt->map);
01402     }
01403 
01404     /* free sql statement */
01405 
01406     OCI_FREE(stmt->sql);
01407 
01408     stmt->rsts  = NULL;
01409     stmt->sql   = NULL;
01410     stmt->map   = NULL;
01411     stmt->batch = NULL;
01412 
01413     stmt->status     = OCI_STMT_CLOSED;
01414     stmt->type       = OCI_UNKNOWN;
01415     stmt->bind_array = FALSE;
01416 
01417     stmt->nb_iters      = 1;
01418     stmt->nb_iters_init = 1;
01419     stmt->dynidx        = 0;
01420     stmt->err_pos       = 0;
01421 
01422     return res;
01423 }
01424 
01425 /* --------------------------------------------------------------------------------------------- *
01426  * OCI_StatementClose
01427  * --------------------------------------------------------------------------------------------- */
01428 
01429 boolean OCI_StatementClose
01430 (
01431     OCI_Statement *stmt
01432 )
01433 {
01434     boolean res    = TRUE;
01435     OCI_Error *err = NULL;
01436 
01437     OCI_CHECK_PTR(OCI_IPC_STATEMENT, stmt, FALSE);
01438 
01439     /* clear statement reference from current error object */
01440 
01441     err = OCI_ErrorGet(FALSE, FALSE);
01442 
01443     if (err != NULL && err->stmt == stmt)
01444         err->stmt = NULL;
01445 
01446     /* reset data */
01447 
01448     res = OCI_StatementReset(stmt);
01449 
01450     if (stmt->stmt != NULL && stmt->hstate == OCI_OBJECT_ALLOCATED)
01451     {
01452         OCI_HandleFree((dvoid *) stmt->stmt, (ub4) OCI_HTYPE_STMT);
01453     }
01454 
01455     return res;
01456 }
01457 
01458 /* --------------------------------------------------------------------------------------------- *
01459  * OCI_BatchErrorClear
01460  * --------------------------------------------------------------------------------------------- */
01461 
01462 boolean OCI_BatchErrorClear
01463 (
01464     OCI_Statement *stmt
01465 )
01466 {
01467     boolean res = FALSE;
01468 
01469     if (stmt->batch != NULL)
01470     {
01471         /* free internal array of OCI_Errors */
01472 
01473         OCI_FREE(stmt->batch->errs);
01474 
01475         /* free batch structure */
01476 
01477         OCI_FREE(stmt->batch);
01478 
01479         res = TRUE;
01480     }
01481 
01482     return res;
01483 }
01484 
01485 /* --------------------------------------------------------------------------------------------- *
01486  * OCI_BatchErrorsInit
01487  * --------------------------------------------------------------------------------------------- */
01488 
01489 boolean OCI_BatchErrorInit
01490 (
01491     OCI_Statement *stmt
01492 )
01493 {
01494     boolean res   = TRUE;
01495     ub4 err_count = 0;
01496 
01497     OCI_BatchErrorClear(stmt);
01498 
01499     /* all OCI call here are not checked for errors as we already dealing
01500        with an array DML error */
01501 
01502     OCIAttrGet((dvoid *) stmt->stmt, (ub4) OCI_HTYPE_STMT,
01503                (dvoid *) &err_count, (ub4 *) NULL,
01504                (ub4) OCI_ATTR_NUM_DML_ERRORS, stmt->con->err);
01505 
01506     if (err_count > 0)
01507     {
01508         OCIError *hndl = NULL;
01509 
01510         /* allocate batch error structure */
01511 
01512         stmt->batch = (OCI_BatchErrors *) OCI_MemAlloc(OCI_IPC_BATCH_ERRORS,
01513                                                        sizeof(*stmt->batch),
01514                                                        (size_t) 1, TRUE);
01515 
01516         res = (stmt->batch != NULL);
01517 
01518         /* allocate array of error objects */
01519 
01520         if (res == TRUE)
01521         {
01522             stmt->batch->errs = (OCI_Error *) OCI_MemAlloc(OCI_IPC_ERROR,
01523                                                            sizeof(*stmt->batch->errs),
01524                                                            (size_t) err_count, TRUE);
01525 
01526             res = (stmt->batch->errs != NULL);
01527         }
01528 
01529         if (res == TRUE)
01530         {
01531             /* allocate OCI error handle */
01532 
01533             OCI_HandleAlloc((dvoid  *) OCILib.env,
01534                             (dvoid **) (void *) &hndl,
01535                             (ub4) OCI_HTYPE_ERROR,
01536                             (size_t) 0, (dvoid **) NULL);
01537 
01538             res = (hndl != NULL);
01539         }
01540 
01541         /* loop on the OCI errors to fill OCILIB error objects */
01542 
01543         if (res == TRUE)
01544         {
01545             ub4 i;
01546 
01547             stmt->batch->count = err_count;
01548 
01549             for (i = 0; i < stmt->batch->count; i++)
01550             {
01551                 int osize  = -1;
01552                 void *ostr = NULL;
01553 
01554                 OCI_Error *err = &stmt->batch->errs[i];
01555 
01556                 OCIParamGet((dvoid *) stmt->con->err, OCI_HTYPE_ERROR,
01557                             stmt->con->err, (dvoid **) (void *) &hndl, i);
01558 
01559                 /* get row offset */
01560 
01561                 OCIAttrGet((dvoid *) hndl, (ub4) OCI_HTYPE_ERROR,
01562                            (void *) &err->row, (ub4 *) NULL,
01563                            (ub4) OCI_ATTR_DML_ROW_OFFSET, stmt->con->err);
01564 
01565                 /* fill error attributes */
01566 
01567                 err->type = OCI_ERR_ORACLE;
01568                 err->con  = stmt->con;
01569                 err->stmt = stmt;
01570 
01571                 /* OCILIB indexes start at 1 */
01572 
01573                 err->row++;
01574 
01575                 /* get error string */
01576 
01577                 osize = (int) msizeof(err->str) - 1;
01578 
01579                 ostr = OCI_GetInputMetaString(err->str, &osize);
01580 
01581                 OCIErrorGet((dvoid *) hndl,
01582                             (ub4) 1,
01583                             (OraText *) NULL, &err->ocode,
01584                             (OraText *) ostr,
01585                             (ub4) osize,
01586                             (ub4) OCI_HTYPE_ERROR);
01587 
01588                 OCI_GetOutputMetaString(ostr, err->str, &osize);
01589                 OCI_ReleaseMetaString(ostr);
01590             }
01591         }
01592 
01593         /* release error handle */
01594 
01595         if (hndl != NULL)
01596         {
01597             OCI_HandleFree(hndl, OCI_HTYPE_ERROR);
01598         }
01599     }
01600 
01601     return res;
01602 }
01603 
01604 /* --------------------------------------------------------------------------------------------- *
01605  * OCI_ExecuteInternal
01606  * --------------------------------------------------------------------------------------------- */
01607 
01608 boolean OCI_API OCI_ExecuteInternal
01609 (
01610     OCI_Statement *stmt,
01611     ub4            mode
01612 )
01613 {
01614     boolean res  = TRUE;
01615     sword status = OCI_SUCCESS;
01616     ub4 iters    = 0;
01617 
01618     OCI_CHECK_PTR(OCI_IPC_STATEMENT, stmt, FALSE);
01619     OCI_CHECK_STMT_STATUS(stmt, OCI_STMT_CLOSED, FALSE);
01620 
01621     /* set up iters and mode values for execution */
01622 
01623     if (stmt->type == OCI_CST_SELECT)
01624     {
01625         mode = stmt->exec_mode;
01626     }
01627     else
01628     {
01629         iters = stmt->nb_iters;
01630 
01631         /* for array DML, use batch error mode */
01632 
01633         if (iters > 1)
01634         {
01635             mode = mode | OCI_BATCH_ERRORS;
01636         }
01637     }
01638 
01639     /* reset batch errors */
01640 
01641     res = OCI_BatchErrorClear(stmt);
01642 
01643     /* check bind objects for updating their null indicator status */
01644 
01645     res = OCI_BindCheck(stmt);
01646 
01647     /* check current resultsets */
01648 
01649     if ((res == TRUE) && (stmt->rsts != NULL))
01650     {
01651         /* resultsets are freed before any prepare operations.
01652            So, if we got ones here, it means the same SQL order
01653            is re-executed */
01654 
01655         if (stmt->type == OCI_CST_SELECT)
01656         {
01657             /* just reinitialize the current resultet */
01658 
01659             res = OCI_ResultsetInit(stmt->rsts[0]);
01660         }
01661         else
01662         {
01663             /* Must free previous resulsets for 'returning into'
01664                SQL orders that can produce multiple resulsets */
01665 
01666             res = OCI_ReleaseResultsets(stmt);
01667         }
01668     }
01669 
01670     /* Oracle execute call */
01671 
01672     status = OCIStmtExecute(stmt->con->cxt, stmt->stmt, stmt->con->err, iters,
01673                             (ub4) 0, (OCISnapshot *) NULL, (OCISnapshot *) NULL,
01674                             mode);
01675 
01676     /* reset input binds indicators status even if execution failed */
01677 
01678     OCI_BindReset(stmt);
01679 
01680     /* check result */
01681 
01682     res = ((status == OCI_SUCCESS) ||
01683            (status == OCI_SUCCESS_WITH_INFO) ||
01684            (status == OCI_NEED_DATA));
01685 
01686     if (status == OCI_SUCCESS_WITH_INFO)
01687     {
01688         OCI_ExceptionOCI(stmt->con->err, stmt->con, stmt, TRUE);
01689     }
01690 
01691     /* on batch mode, check if any error occured */
01692 
01693     if (mode & OCI_BATCH_ERRORS)
01694     {
01695         /* build batch error list if the statement is array DML */
01696 
01697         OCI_BatchErrorInit(stmt);
01698 
01699         if (stmt->batch != NULL)
01700             res = (stmt->batch->count == 0);
01701     }
01702 
01703     /* update status on success */
01704 
01705     if (res == TRUE)
01706     {
01707         stmt->status = OCI_STMT_EXECUTED;
01708 
01709         /* commit if necessary */
01710 
01711         if (stmt->con->autocom == TRUE)
01712             OCI_Commit(stmt->con);
01713     }
01714     else
01715     {
01716         /* get parse error position type */
01717 
01718         /* (one of the rare OCI call not enclosed with a OCI_CALLX macro ...) */
01719 
01720         OCIAttrGet((dvoid *) stmt->stmt, (ub4) OCI_HTYPE_STMT,
01721                    (dvoid *) &stmt->err_pos, (ub4 *) NULL,
01722                    (ub4) OCI_ATTR_PARSE_ERROR_OFFSET, stmt->con->err);
01723 
01724         /* raise exception */
01725 
01726         OCI_ExceptionOCI(stmt->con->err, stmt->con, stmt, FALSE);
01727     }
01728 
01729     OCI_RESULT(res);
01730 
01731     return res;
01732 }
01733 
01734 /* ********************************************************************************************* *
01735  *                            PUBLIC FUNCTIONS
01736  * ********************************************************************************************* */
01737 
01738 /* --------------------------------------------------------------------------------------------- *
01739  * OCI_StatementCreate
01740  * --------------------------------------------------------------------------------------------- */
01741 
01742 OCI_Statement * OCI_API OCI_StatementCreate
01743 (
01744     OCI_Connection *con
01745 )
01746 {
01747     OCI_Statement *stmt = NULL;
01748     OCI_Item *item      = NULL;
01749 
01750     OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, NULL);
01751 
01752     /* create statement object */
01753 
01754     item = OCI_ListAppend(con->stmts, sizeof(*stmt));
01755 
01756     if (item != NULL)
01757     {
01758         stmt = OCI_StatementInit(con, (OCI_Statement **) &item->data, NULL, FALSE);
01759     }
01760 
01761     OCI_RESULT(stmt != NULL);
01762 
01763     return stmt;
01764 }
01765 
01766 /* --------------------------------------------------------------------------------------------- *
01767  * OCI_StatementFree
01768  * --------------------------------------------------------------------------------------------- */
01769 
01770 boolean OCI_API OCI_StatementFree
01771 (
01772     OCI_Statement *stmt
01773 )
01774 {
01775     boolean res = FALSE;
01776 
01777     OCI_CHECK_PTR(OCI_IPC_STATEMENT, stmt, FALSE);
01778 
01779     OCI_CHECK_OBJECT_FETCHED(stmt, FALSE);
01780 
01781     res = OCI_StatementClose(stmt);
01782 
01783     OCI_ListRemove(stmt->con->stmts, stmt);
01784 
01785     OCI_FREE(stmt);
01786 
01787     OCI_RESULT(res);
01788 
01789     return res;
01790 }
01791 
01792 /* --------------------------------------------------------------------------------------------- *
01793  * OCI_ReleaseResultsets
01794  * --------------------------------------------------------------------------------------------- */
01795 
01796 boolean OCI_API OCI_ReleaseResultsets
01797 (
01798     OCI_Statement *stmt
01799 )
01800 {
01801     boolean res = TRUE;
01802     ub4 i, nb_err = 0;
01803 
01804     OCI_CHECK_PTR(OCI_IPC_STATEMENT, stmt, FALSE);
01805 
01806     if (stmt->rsts != NULL)
01807     {
01808         for (i = 0; i  < stmt->nb_rs; i++)
01809         {
01810             if (stmt->rsts[i] != NULL)
01811             {
01812                 if (FALSE == OCI_ResultsetFree(stmt->rsts[i]))
01813                     nb_err++;
01814             }
01815         }
01816 
01817         OCI_FREE(stmt->rsts);
01818     }
01819 
01820     res = (nb_err == 0);
01821 
01822     OCI_RESULT(res);
01823 
01824     return res;
01825 }
01826 
01827 /* --------------------------------------------------------------------------------------------- *
01828  * OCI_Prepare
01829  * --------------------------------------------------------------------------------------------- */
01830 
01831 boolean OCI_API OCI_Prepare
01832 (
01833     OCI_Statement *stmt,
01834     const mtext   *sql
01835 )
01836 {
01837     boolean res = TRUE;
01838     void *ostr  = NULL;
01839     int osize   = -1;
01840 
01841     OCI_CHECK_PTR(OCI_IPC_STATEMENT, stmt, FALSE);
01842     OCI_CHECK_PTR(OCI_IPC_STRING, sql, FALSE);
01843 
01844     /* reset statement */
01845 
01846     res = OCI_StatementReset(stmt);
01847 
01848     if (res == TRUE)
01849     {
01850         /* store SQL */
01851 
01852         stmt->sql = mtsdup(sql);
01853 
01854         ostr = OCI_GetInputMetaString(stmt->sql, &osize);
01855 
01856         /* prepare SQL */
01857 
01858         OCI_CALL1
01859         (
01860             res, stmt->con, stmt,
01861 
01862             OCIStmtPrepare(stmt->stmt,stmt->con->err, (OraText *) ostr,
01863                            (ub4) osize, (ub4) OCI_NTV_SYNTAX, (ub4) OCI_DEFAULT)
01864         )
01865 
01866         OCI_ReleaseMetaString(ostr);
01867 
01868         /* get statement type */
01869 
01870         OCI_CALL1
01871         (
01872             res, stmt->con, stmt,
01873 
01874             OCIAttrGet((dvoid *) stmt->stmt, (ub4) OCI_HTYPE_STMT,
01875                        (dvoid *) &stmt->type, (ub4 *) NULL,
01876                        (ub4) OCI_ATTR_STMT_TYPE, stmt->con->err)
01877         )
01878     }
01879 
01880     /* update statement status */
01881 
01882     if (res == TRUE)
01883         stmt->status = OCI_STMT_PREPARED;
01884 
01885     OCI_RESULT(res);
01886 
01887     return res;
01888 }
01889 
01890 /* --------------------------------------------------------------------------------------------- *
01891  * OCI_Execute
01892  * --------------------------------------------------------------------------------------------- */
01893 
01894 boolean OCI_API OCI_Execute
01895 (
01896     OCI_Statement *stmt
01897 )
01898 {
01899     return OCI_ExecuteInternal(stmt, OCI_DEFAULT);
01900 }
01901 
01902 /* --------------------------------------------------------------------------------------------- *
01903  * OCI_ExecuteStmt
01904  * --------------------------------------------------------------------------------------------- */
01905 
01906 boolean OCI_API OCI_ExecuteStmt
01907 (
01908     OCI_Statement *stmt,
01909     const mtext   *sql
01910 )
01911 {
01912     return (OCI_Prepare(stmt, sql) && OCI_ExecuteInternal(stmt, OCI_DEFAULT));
01913 }
01914 
01915 /* --------------------------------------------------------------------------------------------- *
01916  * OCI_Parse
01917  * --------------------------------------------------------------------------------------------- */
01918 
01919 boolean OCI_API OCI_Parse
01920 (
01921     OCI_Statement *stmt,
01922     const mtext   *sql
01923 )
01924 {
01925     return (OCI_Prepare(stmt, sql) && OCI_ExecuteInternal(stmt, OCI_PARSE_ONLY));
01926 }
01927 
01928 /* --------------------------------------------------------------------------------------------- *
01929  * OCI_PrepareFmt
01930  * --------------------------------------------------------------------------------------------- */
01931 
01932 boolean OCI_PrepareFmt
01933 (
01934     OCI_Statement *stmt,
01935     const mtext   *sql,
01936     ...
01937 )
01938 {
01939     boolean res    = FALSE;
01940     mtext *sql_fmt = NULL;
01941     va_list args;
01942     int size;
01943 
01944     OCI_CHECK_PTR(OCI_IPC_STATEMENT, stmt, FALSE);
01945     OCI_CHECK_PTR(OCI_IPC_STRING, sql, FALSE);
01946 
01947     /* first, get buffer size */
01948 
01949     va_start(args, sql);
01950 
01951     size = OCI_ParseSqlFmt(stmt, NULL, sql, &args);
01952 
01953     va_end(args);
01954 
01955     if (size > 0)
01956     {
01957         /* allocate buffer */
01958 
01959         sql_fmt = (mtext *) OCI_MemAlloc(OCI_IPC_STRING, sizeof(mtext),
01960                                          (size_t) (size+1), TRUE);
01961 
01962         if (sql_fmt != NULL)
01963         {
01964             /* format buffer */
01965 
01966             va_start(args, sql);
01967 
01968             if (OCI_ParseSqlFmt(stmt, sql_fmt, sql, &args) > 0)
01969             {
01970                 /* parse buffer */
01971 
01972                 res = OCI_Prepare(stmt, sql_fmt);
01973             }
01974 
01975             va_end(args);
01976 
01977             OCI_FREE(sql_fmt);
01978         }
01979     }
01980 
01981     OCI_RESULT(res);
01982 
01983     return res;
01984 }
01985 
01986 /* --------------------------------------------------------------------------------------------- *
01987  * OCI_ExecuteStmtFmt
01988  * --------------------------------------------------------------------------------------------- */
01989 
01990 boolean OCI_ExecuteStmtFmt
01991 (
01992     OCI_Statement *stmt,
01993     const mtext   *sql,
01994     ...
01995 )
01996 {
01997     boolean res    = FALSE;
01998     mtext *sql_fmt = NULL;
01999     va_list args;
02000     int size;
02001 
02002     OCI_CHECK_PTR(OCI_IPC_STATEMENT, stmt, FALSE);
02003     OCI_CHECK_PTR(OCI_IPC_STRING, sql, FALSE);
02004 
02005     /* first, get buffer size */
02006 
02007     va_start(args, sql);
02008 
02009     size = OCI_ParseSqlFmt(stmt, NULL, sql, &args);
02010 
02011     va_end(args);
02012 
02013     if (size > 0)
02014     {
02015         /* allocate buffer */
02016 
02017         sql_fmt = (mtext *) OCI_MemAlloc(OCI_IPC_STRING, sizeof(mtext),
02018                                          (size_t) (size+1), TRUE);
02019 
02020         if (sql_fmt != NULL)
02021         {
02022             /* format buffer */
02023 
02024             va_start(args, sql);
02025 
02026             if (OCI_ParseSqlFmt(stmt, sql_fmt, sql, &args) > 0)
02027             {
02028                 /* prepare and execute SQL buffer */
02029 
02030                 res = (OCI_Prepare(stmt, sql_fmt) &&
02031                        OCI_ExecuteInternal(stmt, OCI_DEFAULT));
02032             }
02033 
02034             va_end(args);
02035 
02036             OCI_FREE(sql_fmt);
02037         }
02038     }
02039 
02040     OCI_RESULT(res);
02041 
02042     return res;
02043 }
02044 
02045 /* --------------------------------------------------------------------------------------------- *
02046  * OCI_ParseFmt
02047  * --------------------------------------------------------------------------------------------- */
02048 
02049 boolean OCI_ParseFmt
02050 (
02051     OCI_Statement *stmt,
02052     const mtext   *sql,
02053     ...
02054 )
02055 {
02056     boolean res    = FALSE;
02057     mtext *sql_fmt = NULL;
02058     va_list args;
02059     int size;
02060 
02061     OCI_CHECK_PTR(OCI_IPC_STATEMENT, stmt, FALSE);
02062     OCI_CHECK_PTR(OCI_IPC_STRING, sql, FALSE);
02063 
02064     /* first, get buffer size */
02065 
02066     va_start(args, sql);
02067 
02068     size = OCI_ParseSqlFmt(stmt, NULL, sql, &args);
02069 
02070     va_end(args);
02071 
02072     if (size > 0)
02073     {
02074         /* allocate buffer */
02075 
02076         sql_fmt = (mtext *) OCI_MemAlloc(OCI_IPC_STRING, sizeof(mtext),
02077                                          (size_t) (size+1), TRUE);
02078 
02079         if (sql_fmt != NULL)
02080         {
02081             /* format buffer */
02082 
02083             va_start(args, sql);
02084 
02085             if (OCI_ParseSqlFmt(stmt, sql_fmt, sql, &args) > 0)
02086             {
02087                 /* prepare and execute SQL buffer */
02088 
02089                 res = (OCI_Prepare(stmt, sql_fmt) &&
02090                        OCI_ExecuteInternal(stmt, OCI_PARSE_ONLY));
02091             }
02092 
02093             va_end(args);
02094 
02095             OCI_FREE(sql_fmt);
02096         }
02097     }
02098 
02099     OCI_RESULT(res);
02100 
02101     return res;
02102 }
02103 
02104 /* --------------------------------------------------------------------------------------------- *
02105  * OCI_Immediate
02106  * --------------------------------------------------------------------------------------------- */
02107 
02108 boolean OCI_Immediate
02109 (
02110     OCI_Connection *con,
02111     const mtext    *sql,
02112     ...
02113 )
02114 {
02115     OCI_Statement *stmt = NULL;
02116     boolean res         = FALSE;
02117     va_list args;
02118 
02119     OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, FALSE);
02120     OCI_CHECK_PTR(OCI_IPC_STRING, sql, FALSE);
02121 
02122     /* First, execute SQL */
02123 
02124     stmt = OCI_StatementCreate(con);
02125 
02126     if (stmt != NULL)
02127     {
02128         if (OCI_ExecuteStmt(stmt, sql))
02129         {
02130             /* get resultset and set up variables */
02131 
02132             if (OCI_GetStatementType(stmt) == OCI_CST_SELECT)
02133             {
02134                 va_start(args, sql);
02135 
02136                 res = OCI_FetchIntoUserVariables(stmt, args);
02137 
02138                 va_end(args);
02139             }
02140         }
02141 
02142         OCI_StatementFree(stmt);
02143     }
02144 
02145     OCI_RESULT(res);
02146 
02147     return res;
02148 }
02149 
02150 /* --------------------------------------------------------------------------------------------- *
02151  * OCI_ImmediateFmt
02152  * --------------------------------------------------------------------------------------------- */
02153 
02154 boolean OCI_ImmediateFmt
02155 (
02156     OCI_Connection *con,
02157     const mtext    *sql,
02158     ...
02159 )
02160 {
02161     OCI_Statement *stmt = NULL;
02162     mtext *sql_fmt      = NULL;
02163     boolean res         = FALSE;
02164     va_list args;
02165     int size;
02166 
02167     OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, FALSE);
02168     OCI_CHECK_PTR(OCI_IPC_STRING, sql, FALSE);
02169 
02170     stmt = OCI_StatementCreate(con);
02171 
02172     if (stmt != NULL)
02173     {
02174         /* first, get buffer size */
02175 
02176         va_start(args, sql);
02177 
02178         size = OCI_ParseSqlFmt(stmt, NULL, sql, &args);
02179 
02180         va_end(args);
02181 
02182         if (size > 0)
02183         {
02184             /* allocate buffer */
02185 
02186             sql_fmt = (mtext *) OCI_MemAlloc(OCI_IPC_STRING, sizeof(mtext),
02187                                              (size_t) (size+1), TRUE);
02188 
02189             if (sql_fmt != NULL)
02190             {
02191                 /* format buffer */
02192 
02193                 va_start(args, sql);
02194 
02195                 if (OCI_ParseSqlFmt(stmt, sql_fmt, sql, &args) > 0)
02196                 {
02197                     /* prepare and execute SQL buffer */
02198 
02199                     res = (OCI_Prepare(stmt, sql_fmt) &&
02200                            OCI_ExecuteInternal(stmt, OCI_DEFAULT));
02201 
02202                     /* get resultset and set up variables */
02203 
02204                     if (res && (OCI_GetStatementType(stmt) == OCI_CST_SELECT))
02205                     {
02206                         res = OCI_FetchIntoUserVariables(stmt, args);
02207                     }
02208                 }
02209 
02210                 va_end(args);
02211 
02212                 OCI_FREE(sql_fmt);
02213             }
02214         }
02215 
02216         OCI_StatementFree(stmt);
02217     }
02218 
02219     OCI_RESULT(res);
02220 
02221     return res;
02222 }
02223 
02224 /* --------------------------------------------------------------------------------------------- *
02225  * OCI_BindArraySetSize
02226  * --------------------------------------------------------------------------------------------- */
02227 
02228 boolean OCI_API OCI_BindArraySetSize
02229 (
02230     OCI_Statement *stmt,
02231     unsigned int   size
02232 )
02233 {
02234     boolean res = TRUE;
02235 
02236     OCI_CHECK_PTR(OCI_IPC_STATEMENT, stmt, FALSE);
02237 
02238     OCI_CHECK_MIN(stmt->con, stmt, size, 1, FALSE);
02239 
02240     OCI_CHECK_STMT_STATUS(stmt, OCI_STMT_CLOSED, FALSE);
02241 
02242     /* if the statements already has binds, we need to check if the new size is
02243        not greater than the initial size
02244     */
02245 
02246     if ((stmt->nb_ubinds > 0) && (stmt->nb_iters_init < size))
02247     {
02248         OCI_ExceptionBindArraySize(stmt, stmt->nb_iters_init,
02249                                    stmt->nb_iters, size);
02250 
02251         res = FALSE;
02252     }
02253     else
02254     {
02255         stmt->nb_iters   = size;
02256         stmt->bind_array = TRUE;
02257 
02258         if (stmt->nb_ubinds == 0)
02259             stmt->nb_iters_init = stmt->nb_iters;
02260     }
02261 
02262     OCI_RESULT(res);
02263 
02264     return res;
02265 }
02266 
02267 /* --------------------------------------------------------------------------------------------- *
02268  * OCI_BindArrayGetSize
02269  * --------------------------------------------------------------------------------------------- */
02270 
02271 unsigned int OCI_API OCI_BindArrayGetSize
02272 (
02273     OCI_Statement *stmt
02274 )
02275 {
02276     OCI_CHECK_PTR(OCI_IPC_STATEMENT, stmt, FALSE);
02277 
02278     OCI_RESULT(TRUE);
02279 
02280     return stmt->nb_iters;
02281 }
02282 
02283 /* --------------------------------------------------------------------------------------------- *
02284  * OCI_AllowRebinding
02285  * --------------------------------------------------------------------------------------------- */
02286 
02287 OCI_EXPORT boolean OCI_API OCI_AllowRebinding
02288 (
02289     OCI_Statement *stmt,
02290     boolean        value
02291 )
02292 {
02293     OCI_CHECK_PTR(OCI_IPC_STATEMENT, stmt, FALSE);
02294 
02295     OCI_RESULT(TRUE);
02296 
02297     stmt->bind_reuse = value;
02298 
02299     return TRUE;
02300 }
02301 
02302 /* --------------------------------------------------------------------------------------------- *
02303  * OCI_BindShort
02304  * --------------------------------------------------------------------------------------------- */
02305 
02306 boolean OCI_API OCI_BindShort
02307 (
02308     OCI_Statement *stmt,
02309     const mtext   *name,
02310     short         *data
02311 )
02312 {
02313     OCI_CHECK_BIND_CALL(stmt, name, data, OCI_IPC_SHORT);
02314 
02315     return OCI_BindData(stmt, data, sizeof(short), name, OCI_CDT_NUMERIC,
02316                         SQLT_INT, OCI_BIND_INPUT, OCI_NUM_SHORT, NULL, 0);
02317 }
02318 
02319 /* --------------------------------------------------------------------------------------------- *
02320  * OCI_BindArrayOfShorts
02321  * --------------------------------------------------------------------------------------------- */
02322 
02323 boolean OCI_API OCI_BindArrayOfShorts
02324 (
02325     OCI_Statement *stmt,
02326     const mtext   *name,
02327     short         *data,
02328     unsigned int   nbelem
02329 )
02330 {
02331     OCI_CHECK_BIND_CALL(stmt, name, data, OCI_IPC_SHORT);
02332 
02333     return OCI_BindData(stmt, data, sizeof(short), name, OCI_CDT_NUMERIC,
02334                         SQLT_INT, OCI_BIND_INPUT, OCI_NUM_SHORT, NULL, nbelem);
02335 }
02336 
02337 /* --------------------------------------------------------------------------------------------- *
02338  * OCI_BindUnsignedShort
02339  * --------------------------------------------------------------------------------------------- */
02340 
02341 boolean OCI_API OCI_BindUnsignedShort
02342 (
02343     OCI_Statement  *stmt,
02344     const mtext    *name,
02345     unsigned short *data
02346 )
02347 {
02348     OCI_CHECK_BIND_CALL(stmt, name, data, OCI_IPC_SHORT);
02349 
02350     return OCI_BindData(stmt, data, sizeof(unsigned short), name, OCI_CDT_NUMERIC,
02351                         SQLT_UIN, OCI_BIND_INPUT, OCI_NUM_USHORT, NULL, 0);
02352 }
02353 
02354 /* --------------------------------------------------------------------------------------------- *
02355  * OCI_BindArrayOfUnsignedShorts
02356  * --------------------------------------------------------------------------------------------- */
02357 
02358 boolean OCI_API OCI_BindArrayOfUnsignedShorts
02359 (
02360     OCI_Statement  *stmt,
02361     const mtext    *name,
02362     unsigned short *data,
02363     unsigned int    nbelem
02364 )
02365 {
02366     OCI_CHECK_BIND_CALL(stmt, name, data, OCI_IPC_SHORT);
02367 
02368     return OCI_BindData(stmt, data, sizeof(unsigned short), name, OCI_CDT_NUMERIC,
02369                         SQLT_UIN, OCI_BIND_INPUT, OCI_NUM_USHORT, NULL, nbelem);
02370 }
02371 
02372 /* --------------------------------------------------------------------------------------------- *
02373  * OCI_BindInt
02374  * --------------------------------------------------------------------------------------------- */
02375 
02376 boolean OCI_API OCI_BindInt
02377 (
02378     OCI_Statement *stmt,
02379     const mtext   *name,
02380     int           *data
02381 )
02382 {
02383     OCI_CHECK_BIND_CALL(stmt, name, data, OCI_IPC_INT);
02384 
02385     return OCI_BindData(stmt, data, sizeof(int), name, OCI_CDT_NUMERIC,
02386                         SQLT_INT, OCI_BIND_INPUT, OCI_NUM_INT, NULL, 0);
02387 }
02388 
02389 /* --------------------------------------------------------------------------------------------- *
02390  * OCI_BindArrayOfInts
02391  * --------------------------------------------------------------------------------------------- */
02392 
02393 boolean OCI_API OCI_BindArrayOfInts
02394 (
02395     OCI_Statement *stmt,
02396     const mtext   *name,
02397     int           *data,
02398     unsigned int   nbelem
02399 )
02400 {
02401     OCI_CHECK_BIND_CALL(stmt, name, data, OCI_IPC_INT);
02402 
02403     return OCI_BindData(stmt, data, sizeof(int), name, OCI_CDT_NUMERIC,
02404                         SQLT_INT, OCI_BIND_INPUT, OCI_NUM_INT, NULL, nbelem);
02405 }
02406 
02407 /* --------------------------------------------------------------------------------------------- *
02408  * OCI_BindUnsignedInt
02409  * --------------------------------------------------------------------------------------------- */
02410 
02411 boolean OCI_API OCI_BindUnsignedInt
02412 (
02413     OCI_Statement *stmt,
02414     const mtext   *name,
02415     unsigned int  *data
02416 )
02417 {
02418     OCI_CHECK_BIND_CALL(stmt, name, data, OCI_IPC_INT);
02419 
02420     return OCI_BindData(stmt, data, sizeof(unsigned int), name, OCI_CDT_NUMERIC,
02421                         SQLT_UIN, OCI_BIND_INPUT, OCI_NUM_UINT, NULL, 0);
02422 }
02423 
02424 /* --------------------------------------------------------------------------------------------- *
02425  * OCI_BindArrayOfUnsignedInts
02426  * --------------------------------------------------------------------------------------------- */
02427 
02428 boolean OCI_API OCI_BindArrayOfUnsignedInts
02429 (
02430     OCI_Statement *stmt,
02431     const mtext   *name,
02432     unsigned int  *data,
02433     unsigned int   nbelem
02434 )
02435 {
02436     OCI_CHECK_BIND_CALL(stmt, name, data, OCI_IPC_INT);
02437 
02438     return OCI_BindData(stmt, data, sizeof(unsigned int), name, OCI_CDT_NUMERIC,
02439                         SQLT_UIN, OCI_BIND_INPUT, OCI_NUM_UINT, NULL, nbelem);
02440 }
02441 
02442 /* --------------------------------------------------------------------------------------------- *
02443  * OCI_BindBigInt
02444  * --------------------------------------------------------------------------------------------- */
02445 
02446 boolean OCI_API OCI_BindBigInt
02447 (
02448     OCI_Statement *stmt,
02449     const mtext   *name,
02450     big_int       *data
02451 )
02452 {
02453     OCI_CHECK_BIND_CALL(stmt, name, data, OCI_IPC_BIGINT);
02454 
02455     return OCI_BindData(stmt, data, sizeof(OCINumber), name, OCI_CDT_NUMERIC,
02456                         SQLT_VNU, OCI_BIND_INPUT, OCI_NUM_BIGINT, NULL, 0);
02457 }
02458 
02459 /* --------------------------------------------------------------------------------------------- *
02460  * OCI_BindArrayOfBigInts
02461  * --------------------------------------------------------------------------------------------- */
02462 
02463 boolean OCI_API OCI_BindArrayOfBigInts
02464 (
02465     OCI_Statement *stmt,
02466     const mtext   *name,
02467     big_int       *data,
02468     unsigned int   nbelem
02469 )
02470 {
02471     OCI_CHECK_BIND_CALL(stmt, name, data, OCI_IPC_BIGINT);
02472 
02473     return OCI_BindData(stmt, data, sizeof(OCINumber), name, OCI_CDT_NUMERIC,
02474                         SQLT_VNU, OCI_BIND_INPUT, OCI_NUM_BIGINT, NULL, nbelem);
02475 }
02476 
02477 /* --------------------------------------------------------------------------------------------- *
02478  * OCI_BindUnsignedBigInt
02479  * --------------------------------------------------------------------------------------------- */
02480 
02481 boolean OCI_API OCI_BindUnsignedBigInt
02482 (
02483     OCI_Statement *stmt,
02484     const mtext   *name,
02485     big_uint      *data
02486 )
02487 {
02488     OCI_CHECK_BIND_CALL(stmt, name, data, OCI_IPC_BIGINT);
02489 
02490     return OCI_BindData(stmt, data, sizeof(OCINumber), name, OCI_CDT_NUMERIC,
02491                         SQLT_VNU, OCI_BIND_INPUT, OCI_NUM_BIGUINT, NULL, 0);
02492 }
02493 
02494 /* --------------------------------------------------------------------------------------------- *
02495  * OCI_BindArrayOfUnsignedInts
02496  * --------------------------------------------------------------------------------------------- */
02497 
02498 boolean OCI_API OCI_BindArrayOfUnsignedBigInts
02499 (
02500     OCI_Statement *stmt,
02501     const mtext   *name,
02502     big_uint      *data,
02503     unsigned int   nbelem
02504 )
02505 {
02506     OCI_CHECK_BIND_CALL(stmt, name, data, OCI_IPC_BIGINT);
02507 
02508     return OCI_BindData(stmt, data, sizeof(OCINumber), name, OCI_CDT_NUMERIC,
02509                         SQLT_VNU, OCI_BIND_INPUT, OCI_NUM_BIGUINT, NULL, nbelem);
02510 }
02511 
02512 /* --------------------------------------------------------------------------------------------- *
02513  * OCI_BindString
02514  * --------------------------------------------------------------------------------------------- */
02515 
02516 boolean OCI_API OCI_BindString
02517 (
02518     OCI_Statement *stmt,
02519     const mtext   *name,
02520     dtext         *data,
02521     unsigned int   len
02522 )
02523 {
02524     OCI_CHECK_BIND_CALL(stmt, name, data, OCI_IPC_STRING);
02525 
02526     if (len == 0 || len == UINT_MAX)
02527         len = (unsigned int) dtslen(data);
02528 
02529     return OCI_BindData(stmt, data, (len + 1) * (ub4) sizeof(odtext), name,
02530                         OCI_CDT_TEXT, SQLT_STR, OCI_BIND_INPUT, 0, NULL, 0);
02531 }
02532 
02533 /* --------------------------------------------------------------------------------------------- *
02534  * OCI_BindArrayOfStrings
02535  * --------------------------------------------------------------------------------------------- */
02536 
02537 boolean OCI_API OCI_BindArrayOfStrings
02538 (
02539     OCI_Statement *stmt,
02540     const mtext   *name,
02541     dtext         *data,
02542     unsigned int   len,
02543     unsigned int   nbelem
02544 )
02545 {
02546     OCI_CHECK_BIND_CALL(stmt, name, data, OCI_IPC_STRING);
02547 
02548     OCI_CHECK_MIN(stmt->con, stmt, len, 1, FALSE);
02549 
02550     return OCI_BindData(stmt, data, (len + 1) * (ub4) sizeof(odtext), name,
02551                         OCI_CDT_TEXT, SQLT_STR, OCI_BIND_INPUT, 0, NULL, nbelem);
02552 }
02553 
02554 /* --------------------------------------------------------------------------------------------- *
02555  * OCI_BindRaw
02556  * --------------------------------------------------------------------------------------------- */
02557 
02558 boolean OCI_API OCI_BindRaw
02559 (
02560     OCI_Statement *stmt,
02561     const mtext   *name,
02562     void          *data,
02563     unsigned int   len
02564 )
02565 {
02566     OCI_CHECK_BIND_CALL(stmt, name, data, OCI_IPC_VOID);
02567 
02568     OCI_CHECK_MIN(stmt->con, stmt, len, 1, FALSE);
02569 
02570     return OCI_BindData(stmt, data, len, name, OCI_CDT_RAW,
02571                         SQLT_BIN, OCI_BIND_INPUT, 0, NULL, 0);
02572 }
02573 
02574 /* --------------------------------------------------------------------------------------------- *
02575  * OCI_BindArrayOfRaws
02576  * --------------------------------------------------------------------------------------------- */
02577 
02578 boolean OCI_API OCI_BindArrayOfRaws
02579 (
02580     OCI_Statement *stmt,
02581     const mtext   *name,
02582     void          *data,
02583     unsigned int   len,
02584     unsigned int   nbelem
02585 )
02586 {
02587     OCI_CHECK_BIND_CALL(stmt, name, data, OCI_IPC_VOID);
02588 
02589     OCI_CHECK_MIN(stmt->con, stmt, len, 1, FALSE);
02590 
02591     return OCI_BindData(stmt, data, len, name, OCI_CDT_RAW,
02592                         SQLT_BIN, OCI_BIND_INPUT, 0, NULL, nbelem);
02593 }
02594 
02595 /* --------------------------------------------------------------------------------------------- *
02596  * OCI_BindDouble
02597  * --------------------------------------------------------------------------------------------- */
02598 
02599 boolean OCI_API OCI_BindDouble
02600 (
02601     OCI_Statement *stmt,
02602     const mtext   *name,
02603     double        *data
02604 )
02605 {
02606     OCI_CHECK_BIND_CALL(stmt, name, data, OCI_IPC_DOUBLE);
02607 
02608     return OCI_BindData(stmt, data, sizeof(double), name, OCI_CDT_NUMERIC,
02609                         SQLT_FLT, OCI_BIND_INPUT, 0, NULL, 0);
02610 }
02611 
02612 /* --------------------------------------------------------------------------------------------- *
02613  * OCI_BindArrayOfDoubles
02614  * --------------------------------------------------------------------------------------------- */
02615 
02616 boolean OCI_API OCI_BindArrayOfDoubles
02617 (
02618     OCI_Statement *stmt,
02619     const mtext   *name,
02620     double        *data,
02621     unsigned int   nbelem
02622 )
02623 {
02624     OCI_CHECK_BIND_CALL(stmt, name, data, OCI_IPC_DOUBLE);
02625 
02626     return OCI_BindData(stmt, data, sizeof(double), name, OCI_CDT_NUMERIC,
02627                         SQLT_FLT, OCI_BIND_INPUT, 0, NULL, nbelem);
02628 }
02629 
02630 /* --------------------------------------------------------------------------------------------- *
02631  * OCI_BindDate
02632  * --------------------------------------------------------------------------------------------- */
02633 
02634 boolean OCI_API OCI_BindDate
02635 (
02636     OCI_Statement *stmt,
02637     const mtext   *name,
02638     OCI_Date      *data
02639 )
02640 {
02641     OCI_CHECK_BIND_CALL(stmt, name, data, OCI_IPC_DATE);
02642 
02643     return OCI_BindData(stmt, data, sizeof(OCIDate), name, OCI_CDT_DATETIME,
02644                         SQLT_ODT, OCI_BIND_INPUT, 0, NULL, 0);
02645 }
02646 
02647 /* --------------------------------------------------------------------------------------------- *
02648  * OCI_BindArrayOfDates
02649  * --------------------------------------------------------------------------------------------- */
02650 
02651 boolean OCI_API OCI_BindArrayOfDates
02652 (
02653     OCI_Statement *stmt,
02654     const mtext   *name,
02655     OCI_Date     **data,
02656     unsigned int   nbelem
02657 )
02658 {
02659     OCI_CHECK_BIND_CALL(stmt, name, data, OCI_IPC_DATE);
02660 
02661     return OCI_BindData(stmt, data, sizeof(OCIDate), name, OCI_CDT_DATETIME,
02662                         SQLT_ODT, OCI_BIND_INPUT, 0, NULL, nbelem);
02663 }
02664 
02665 /* --------------------------------------------------------------------------------------------- *
02666  * OCI_BindTimestamp
02667  * --------------------------------------------------------------------------------------------- */
02668 
02669 boolean OCI_API OCI_BindTimestamp
02670 (
02671     OCI_Statement *stmt,
02672     const mtext   *name,
02673     OCI_Timestamp *data
02674 )
02675 {
02676     int code    = 0;
02677     boolean res = FALSE;
02678 
02679     OCI_CHECK_BIND_CALL(stmt, name, data, OCI_IPC_TIMESTAMP);
02680 
02681     OCI_CHECK_TIMESTAMP_ENABLED(stmt->con, FALSE);
02682 
02683     #if OCI_VERSION_COMPILE >= OCI_9_0
02684 
02685     /* map oracle internal type */
02686 
02687     if (data->type == OCI_TIMESTAMP_TZ)
02688         code = SQLT_TIMESTAMP_TZ;
02689     else if (data->type == OCI_TIMESTAMP_LTZ)
02690         code = SQLT_TIMESTAMP_LTZ;
02691     else
02692         code = SQLT_TIMESTAMP;
02693 
02694     res = OCI_BindData(stmt, data, sizeof(OCIDateTime *), name, OCI_CDT_TIMESTAMP,
02695                        code, OCI_BIND_INPUT, data->type, NULL, 0);
02696 
02697     #else
02698 
02699     OCI_NOT_USED(name);
02700     OCI_NOT_USED(code);
02701     OCI_NOT_USED(code);
02702 
02703     #endif
02704 
02705     return res;
02706 }
02707 
02708 /* --------------------------------------------------------------------------------------------- *
02709  * OCI_BindArrayOfTimestamps
02710  * --------------------------------------------------------------------------------------------- */
02711 
02712 boolean OCI_API OCI_BindArrayOfTimestamps
02713 (
02714     OCI_Statement  *stmt,
02715     const mtext    *name,
02716     OCI_Timestamp **data,
02717     unsigned int    type,
02718     unsigned int    nbelem
02719 )
02720 {
02721     unsigned int code = 0;
02722     boolean res       = FALSE;
02723 
02724     OCI_CHECK_BIND_CALL(stmt, name, data, OCI_IPC_TIMESTAMP);
02725 
02726     OCI_CHECK_TIMESTAMP_ENABLED(stmt->con, FALSE);
02727 
02728     #if OCI_VERSION_COMPILE >= OCI_9_0
02729 
02730     /* map oracle internal type */
02731 
02732     if (type == OCI_TIMESTAMP_TZ)
02733         code = SQLT_TIMESTAMP_TZ;
02734     else if (type == OCI_TIMESTAMP_LTZ)
02735         code = SQLT_TIMESTAMP_LTZ;
02736     else
02737         code = SQLT_TIMESTAMP;
02738 
02739     res =  OCI_BindData(stmt, data, sizeof(OCIDateTime *), name, OCI_CDT_TIMESTAMP,
02740                         code, OCI_BIND_INPUT, type, NULL, nbelem);
02741 
02742     #else
02743 
02744     OCI_NOT_USED(name);
02745     OCI_NOT_USED(type);
02746     OCI_NOT_USED(code);
02747     OCI_NOT_USED(nbelem);
02748 
02749     #endif
02750 
02751     return res;
02752 }
02753 
02754 /* --------------------------------------------------------------------------------------------- *
02755  * OCI_BindInterval
02756  * --------------------------------------------------------------------------------------------- */
02757 
02758 boolean OCI_API OCI_BindInterval
02759 (
02760     OCI_Statement *stmt,
02761     const mtext   *name,
02762     OCI_Interval  *data
02763 )
02764 {
02765     int code    = 0;
02766     boolean res = FALSE;
02767 
02768     OCI_CHECK_BIND_CALL(stmt, name, data, OCI_IPC_INTERVAL);
02769 
02770     OCI_CHECK_INTERVAL_ENABLED(stmt->con, FALSE);
02771 
02772     #if OCI_VERSION_COMPILE >= OCI_9_0
02773 
02774     /* map oracle internal type */
02775 
02776     if (data->type == OCI_INTERVAL_YM)
02777         code = SQLT_INTERVAL_YM;
02778     else if (data->type == OCI_INTERVAL_DS)
02779         code = SQLT_INTERVAL_DS;
02780 
02781     res = OCI_BindData(stmt, data, sizeof(OCIInterval *), name, OCI_CDT_INTERVAL,
02782                        code, OCI_BIND_INPUT, data->type, NULL, 0);
02783 
02784     #else
02785 
02786     OCI_NOT_USED(name);
02787     OCI_NOT_USED(code);
02788 
02789     #endif
02790 
02791     return res;
02792 }
02793 
02794 /* --------------------------------------------------------------------------------------------- *
02795  * OCI_BindArrayOfIntervals
02796  * --------------------------------------------------------------------------------------------- */
02797 
02798 boolean OCI_API OCI_BindArrayOfIntervals
02799 (
02800     OCI_Statement *stmt,
02801     const mtext   *name,
02802     OCI_Interval **data,
02803     unsigned int   type,
02804     unsigned int   nbelem
02805 )
02806 {
02807     unsigned int code = 0;
02808     boolean res       = FALSE;
02809 
02810     OCI_CHECK_BIND_CALL(stmt, name, data, OCI_IPC_INTERVAL);
02811 
02812     OCI_CHECK_INTERVAL_ENABLED(stmt->con, FALSE);
02813 
02814     #if OCI_VERSION_COMPILE >= OCI_9_0
02815 
02816     /* map oracle internal type */
02817 
02818     if (type == OCI_INTERVAL_YM)
02819         code = SQLT_INTERVAL_YM;
02820     else if (type == OCI_INTERVAL_DS)
02821         code = SQLT_INTERVAL_DS;
02822 
02823     res = OCI_BindData(stmt, data, sizeof(OCIInterval *), name, OCI_CDT_INTERVAL,
02824                        code, OCI_BIND_INPUT, type, NULL, nbelem);
02825 
02826     #else
02827 
02828     OCI_NOT_USED(name);
02829     OCI_NOT_USED(type);
02830     OCI_NOT_USED(code);
02831     OCI_NOT_USED(nbelem);
02832 
02833     #endif
02834 
02835     return res;
02836 }
02837 
02838 /* --------------------------------------------------------------------------------------------- *
02839  * OCI_BindObject
02840  * --------------------------------------------------------------------------------------------- */
02841 
02842 boolean OCI_API OCI_BindObject
02843 (
02844     OCI_Statement *stmt,
02845     const mtext   *name,
02846     OCI_Object    *data
02847 )
02848 {
02849     OCI_CHECK_BIND_CALL(stmt, name, data, OCI_IPC_OBJECT);
02850 
02851     return OCI_BindData(stmt, data, sizeof(void*), name, OCI_CDT_OBJECT,
02852                         SQLT_NTY, OCI_BIND_INPUT, 0, data->typinf, 0);
02853 }
02854 
02855 /* --------------------------------------------------------------------------------------------- *
02856  * OCI_BindArrayOfObjects
02857  * --------------------------------------------------------------------------------------------- */
02858 
02859 boolean OCI_API OCI_BindArrayOfObjects
02860 (
02861     OCI_Statement *stmt,
02862     const mtext   *name,
02863     OCI_Object   **data,
02864     OCI_TypeInfo  *typinf,
02865     unsigned int   nbelem
02866 )
02867 {
02868     OCI_CHECK_BIND_CALL(stmt, name, data, OCI_IPC_OBJECT);
02869 
02870     OCI_CHECK_PTR(OCI_IPC_TYPE_INFO, typinf, FALSE);
02871 
02872     return OCI_BindData(stmt, data, sizeof(void *), name, OCI_CDT_OBJECT,
02873                         SQLT_NTY, OCI_BIND_INPUT, 0, typinf, nbelem);
02874 }
02875 
02876 /* --------------------------------------------------------------------------------------------- *
02877  * OCI_BindLob
02878  * --------------------------------------------------------------------------------------------- */
02879 
02880 boolean OCI_API OCI_BindLob
02881 (
02882     OCI_Statement *stmt,
02883     const mtext   *name,
02884     OCI_Lob       *data
02885 )
02886 {
02887     int code = 0;
02888 
02889     OCI_CHECK_BIND_CALL(stmt, name, data, OCI_IPC_LOB);
02890 
02891     /* map oracle internal type */
02892 
02893     if (data->type == OCI_CLOB || data->type == OCI_NCLOB)
02894         code = SQLT_CLOB;
02895     else
02896         code = SQLT_BLOB;
02897 
02898     return OCI_BindData(stmt, data, sizeof(OCILobLocator*), name, OCI_CDT_LOB,
02899                         code, OCI_BIND_INPUT, data->type, NULL, 0);
02900 }
02901 
02902 /* --------------------------------------------------------------------------------------------- *
02903  * OCI_BindArrayOfLobs
02904  * --------------------------------------------------------------------------------------------- */
02905 
02906 boolean OCI_API OCI_BindArrayOfLobs
02907 (
02908     OCI_Statement *stmt,
02909     const mtext   *name,
02910     OCI_Lob      **data,
02911     unsigned int   type,
02912     unsigned int   nbelem
02913 )
02914 {
02915     unsigned int code = 0;
02916 
02917     OCI_CHECK_BIND_CALL(stmt, name, data, OCI_IPC_LOB);
02918 
02919     /* map oracle internal type */
02920 
02921     if (type == OCI_CLOB || type == OCI_NCLOB)
02922         code = SQLT_CLOB;
02923     else
02924         code = SQLT_BLOB;
02925 
02926     return OCI_BindData(stmt, data, sizeof(OCILobLocator*), name, OCI_CDT_LOB,
02927                         code, OCI_BIND_INPUT, type, NULL, nbelem);
02928 }
02929 
02930 /* --------------------------------------------------------------------------------------------- *
02931  * OCI_BindFile
02932  * --------------------------------------------------------------------------------------------- */
02933 
02934 boolean OCI_API OCI_BindFile
02935 (
02936     OCI_Statement *stmt,
02937     const mtext   *name,
02938     OCI_File      *data
02939 )
02940 {
02941     int code = 0;
02942 
02943     OCI_CHECK_BIND_CALL(stmt, name, data, OCI_IPC_FILE);
02944 
02945     /* map oracle internal type */
02946 
02947     if (data->type == OCI_CFILE)
02948         code = SQLT_CFILE;
02949     else
02950         code = SQLT_BFILE;
02951 
02952     return OCI_BindData(stmt, data, sizeof(OCILobLocator*), name, OCI_CDT_FILE,
02953                         code, OCI_BIND_INPUT, data->type, NULL, 0);
02954 }
02955 
02956 /* --------------------------------------------------------------------------------------------- *
02957  * OCI_BindArrayOfFiles
02958  * --------------------------------------------------------------------------------------------- */
02959 
02960 boolean OCI_API OCI_BindArrayOfFiles
02961 (
02962     OCI_Statement *stmt,
02963     const mtext   *name,
02964     OCI_File     **data,
02965     unsigned int   type,
02966     unsigned int   nbelem
02967 )
02968 {
02969     unsigned int code = 0;
02970 
02971     OCI_CHECK_BIND_CALL(stmt, name, data, OCI_IPC_FILE);
02972 
02973     /* map oracle internal type */
02974 
02975     if (type == OCI_CFILE)
02976         code = SQLT_CFILE;
02977     else
02978         code = SQLT_BFILE;
02979 
02980     return OCI_BindData(stmt, data, sizeof(OCILobLocator*), name, OCI_CDT_FILE,
02981                         code, OCI_BIND_INPUT, type, NULL, nbelem);
02982 }
02983 
02984 /* --------------------------------------------------------------------------------------------- *
02985  * OCI_BindRef
02986  * --------------------------------------------------------------------------------------------- */
02987 
02988 boolean OCI_API OCI_BindRef
02989 (
02990     OCI_Statement *stmt,
02991     const mtext   *name,
02992     OCI_Ref       *data
02993 )
02994 {
02995     OCI_CHECK_BIND_CALL(stmt, name, data, OCI_IPC_REF);
02996 
02997     return OCI_BindData(stmt, data, sizeof(OCIRef *), name, OCI_CDT_REF,
02998                         SQLT_REF, OCI_BIND_INPUT, 0, data->typinf, 0);
02999 }
03000 
03001 /* --------------------------------------------------------------------------------------------- *
03002  * OCI_BindArrayOfRefs
03003  * --------------------------------------------------------------------------------------------- */
03004 
03005 boolean OCI_API OCI_BindArrayOfRefs
03006 (
03007     OCI_Statement *stmt,
03008     const mtext   *name,
03009     OCI_Ref      **data,
03010     OCI_TypeInfo  *typinf,
03011     unsigned int   nbelem
03012 )
03013 {
03014     OCI_CHECK_BIND_CALL(stmt, name, data, OCI_IPC_REF);
03015 
03016     return OCI_BindData(stmt, data, sizeof(OCIRef *), name, OCI_CDT_REF,
03017                         SQLT_REF, OCI_BIND_INPUT, 0, typinf, nbelem);
03018 }
03019 
03020 /* --------------------------------------------------------------------------------------------- *
03021  * OCI_BindColl
03022  * --------------------------------------------------------------------------------------------- */
03023 
03024 boolean OCI_API OCI_BindColl
03025 (
03026     OCI_Statement *stmt,
03027     const mtext   *name,
03028     OCI_Coll      *data
03029 )
03030 {
03031     OCI_CHECK_BIND_CALL(stmt, name, data, OCI_IPC_COLLECTION);
03032 
03033     return OCI_BindData(stmt, data, sizeof(OCIColl*), name,
03034                         OCI_CDT_COLLECTION, SQLT_NTY, OCI_BIND_INPUT, 0,
03035                         data->typinf, 0);
03036 }
03037 
03038 /* --------------------------------------------------------------------------------------------- *
03039  * OCI_BindArrayOfColls
03040  * --------------------------------------------------------------------------------------------- */
03041 
03042 boolean OCI_API OCI_BindArrayOfColls
03043 (
03044     OCI_Statement *stmt,
03045     const mtext   *name,
03046     OCI_Coll     **data,
03047     OCI_TypeInfo  *typinf,
03048     unsigned int   nbelem
03049 )
03050 {
03051     OCI_CHECK_BIND_CALL(stmt, name, data, OCI_IPC_COLLECTION);
03052 
03053     return OCI_BindData(stmt, data, sizeof(OCIColl*), name,
03054                         OCI_CDT_COLLECTION, SQLT_NTY, OCI_BIND_INPUT, 0,
03055                         typinf, nbelem);
03056 }
03057 
03058 /* --------------------------------------------------------------------------------------------- *
03059  * OCI_BindStatement
03060  * --------------------------------------------------------------------------------------------- */
03061 
03062 boolean OCI_API OCI_BindStatement
03063 (
03064     OCI_Statement *stmt,
03065     const mtext   *name,
03066     OCI_Statement *data
03067 )
03068 {
03069     boolean res = FALSE;
03070 
03071     OCI_CHECK_BIND_CALL(stmt, name, data, OCI_IPC_STATEMENT);
03072 
03073     OCI_StatementReset(data);
03074 
03075     res = OCI_BindData(stmt, &data->stmt, sizeof(OCIStmt*), name, OCI_CDT_CURSOR,
03076                        SQLT_RSET, OCI_BIND_INPUT, 0, NULL, 0);
03077 
03078     if (res == TRUE)
03079     {
03080         /* Once stmt is executed, Oracle provides a statement handle
03081            ready to be fetched  */
03082 
03083         data->status = OCI_STMT_EXECUTED;
03084         data->type   = OCI_CST_SELECT;
03085     }
03086 
03087     return res;
03088 }
03089 
03090 /* --------------------------------------------------------------------------------------------- *
03091  * OCI_BindLong
03092  * --------------------------------------------------------------------------------------------- */
03093 
03094 boolean OCI_API OCI_BindLong
03095 (
03096     OCI_Statement *stmt,
03097     const mtext   *name,
03098     OCI_Long      *data,
03099     unsigned int   size
03100 )
03101 {
03102     int code = 0;
03103 
03104     OCI_CHECK_BIND_CALL(stmt, name, data, OCI_IPC_LONG);
03105 
03106     /* map oracle internal type */
03107 
03108     if (data->type == OCI_CLONG)
03109         code = SQLT_LNG;
03110     else
03111         code = SQLT_LBI;
03112 
03113     if (data->type == OCI_CLONG)
03114         size *= (unsigned int) sizeof(dtext);
03115 
03116     return OCI_BindData(stmt, data, size, name, OCI_CDT_LONG,
03117                         code, OCI_BIND_INPUT, data->type, NULL, 0);
03118 }
03119 
03120 /* --------------------------------------------------------------------------------------------- *
03121  * OCI_RegisterShort
03122  * --------------------------------------------------------------------------------------------- */
03123 
03124 boolean OCI_API OCI_RegisterShort
03125 (
03126     OCI_Statement *stmt,
03127     const mtext   *name
03128 )
03129 {
03130     OCI_CHECK_REGISTER_CALL(stmt, name);
03131 
03132     return OCI_BindData(stmt, NULL, sizeof(OCINumber), name, OCI_CDT_NUMERIC,
03133                         SQLT_VNU, OCI_BIND_OUTPUT, OCI_NUM_SHORT, NULL, 0);
03134 }
03135 
03136 /* --------------------------------------------------------------------------------------------- *
03137  * OCI_RegisterUnsignedShort
03138  * --------------------------------------------------------------------------------------------- */
03139 
03140 boolean OCI_API OCI_RegisterUnsignedShort
03141 (
03142     OCI_Statement *stmt,
03143     const mtext   *name
03144 )
03145 {
03146     OCI_CHECK_REGISTER_CALL(stmt, name);
03147 
03148     return OCI_BindData(stmt, NULL, sizeof(OCINumber), name, OCI_CDT_NUMERIC,
03149                         SQLT_VNU, OCI_BIND_OUTPUT, OCI_NUM_USHORT, NULL, 0);
03150 }
03151 
03152 /* --------------------------------------------------------------------------------------------- *
03153  * OCI_RegisterInt
03154  * --------------------------------------------------------------------------------------------- */
03155 
03156 boolean OCI_API OCI_RegisterInt
03157 (
03158     OCI_Statement *stmt,
03159     const mtext   *name
03160 )
03161 {
03162     OCI_CHECK_REGISTER_CALL(stmt, name);
03163 
03164     return OCI_BindData(stmt, NULL, sizeof(OCINumber), name, OCI_CDT_NUMERIC,
03165                         SQLT_VNU, OCI_BIND_OUTPUT, OCI_NUM_INT, NULL, 0);
03166 }
03167 
03168 /* --------------------------------------------------------------------------------------------- *
03169  * OCI_RegisterUnsignedInt
03170  * --------------------------------------------------------------------------------------------- */
03171 
03172 boolean OCI_API OCI_RegisterUnsignedInt
03173 (
03174     OCI_Statement *stmt,
03175     const mtext   *name
03176 )
03177 {
03178     OCI_CHECK_REGISTER_CALL(stmt, name);
03179 
03180     return OCI_BindData(stmt, NULL, sizeof(OCINumber), name, OCI_CDT_NUMERIC,
03181                         SQLT_VNU, OCI_BIND_OUTPUT, OCI_NUM_UINT, NULL, 0);
03182 }
03183 
03184 /* --------------------------------------------------------------------------------------------- *
03185  * OCI_RegisterBigInt
03186  * --------------------------------------------------------------------------------------------- */
03187 
03188 boolean OCI_API OCI_RegisterBigInt
03189 (
03190     OCI_Statement *stmt,
03191     const mtext   *name
03192 )
03193 {
03194     OCI_CHECK_REGISTER_CALL(stmt, name);
03195 
03196     return OCI_BindData(stmt, NULL, sizeof(OCINumber), name, OCI_CDT_NUMERIC,
03197                         SQLT_VNU, OCI_BIND_OUTPUT, OCI_NUM_BIGINT, NULL, 0);
03198 }
03199 
03200 /* --------------------------------------------------------------------------------------------- *
03201  * OCI_RegisterUnsignedBigInt
03202  * --------------------------------------------------------------------------------------------- */
03203 
03204 boolean OCI_API OCI_RegisterUnsignedBigInt
03205 (
03206     OCI_Statement *stmt,
03207     const mtext   *name
03208 )
03209 {
03210     OCI_CHECK_REGISTER_CALL(stmt, name);
03211 
03212     return OCI_BindData(stmt, NULL, sizeof(OCINumber), name, OCI_CDT_NUMERIC,
03213                         SQLT_VNU, OCI_BIND_OUTPUT, OCI_NUM_BIGUINT, NULL, 0);
03214 }
03215 
03216 /* --------------------------------------------------------------------------------------------- *
03217  * OCI_RegisterString
03218  * --------------------------------------------------------------------------------------------- */
03219 
03220 boolean OCI_API OCI_RegisterString
03221 (
03222     OCI_Statement *stmt,
03223     const mtext   *name,
03224     unsigned int   len
03225 )
03226 {
03227     OCI_CHECK_REGISTER_CALL(stmt, name);
03228 
03229     OCI_CHECK_MIN(stmt->con, stmt, len, 1, FALSE);
03230 
03231     return OCI_BindData(stmt, NULL, (len + 1) * (ub4) sizeof(odtext), name,
03232                         OCI_CDT_TEXT, SQLT_STR, OCI_BIND_OUTPUT, 0, NULL, 0);
03233 }
03234 
03235 /* --------------------------------------------------------------------------------------------- *
03236  * OCI_RegisterRaw
03237  * --------------------------------------------------------------------------------------------- */
03238 
03239 boolean OCI_API OCI_RegisterRaw
03240 (
03241     OCI_Statement *stmt,
03242     const mtext   *name,
03243     unsigned int   len
03244 )
03245 {
03246     OCI_CHECK_REGISTER_CALL(stmt, name);
03247 
03248     OCI_CHECK_MIN(stmt->con, stmt, len, 1, FALSE);
03249 
03250     return OCI_BindData(stmt, NULL, len, name, OCI_CDT_RAW,
03251                         SQLT_BIN, OCI_BIND_OUTPUT, 0, NULL, 0);
03252 }
03253 
03254 /* --------------------------------------------------------------------------------------------- *
03255  * OCI_RegisterDouble
03256  * --------------------------------------------------------------------------------------------- */
03257 
03258 boolean OCI_API OCI_RegisterDouble
03259 (
03260     OCI_Statement *stmt,
03261     const mtext   *name
03262 )
03263 {
03264     OCI_CHECK_REGISTER_CALL(stmt, name);
03265 
03266     return OCI_BindData(stmt, NULL, sizeof(OCINumber), name, OCI_CDT_NUMERIC,
03267                         SQLT_VNU, OCI_BIND_OUTPUT, OCI_NUM_DOUBLE, NULL, 0);
03268 }
03269 
03270 /* --------------------------------------------------------------------------------------------- *
03271  * OCI_RegisterDate
03272  * --------------------------------------------------------------------------------------------- */
03273 
03274 boolean OCI_API OCI_RegisterDate
03275 (
03276     OCI_Statement *stmt,
03277     const mtext   *name
03278 )
03279 {
03280     int code = SQLT_ODT;
03281     int size = sizeof(OCIDate);
03282 
03283     OCI_CHECK_REGISTER_CALL(stmt, name);
03284 
03285     /* versions of OCI (< 10.2) crashes if SQLT_ODT is passed for output
03286        data with returning clause.
03287        It's an Oracle known bug #3269146 */
03288 
03289     if (OCI_GetVersionConnection(stmt->con) < OCI_10_2)
03290     {
03291         code = SQLT_DAT;
03292         size = 7;
03293     }
03294 
03295     return OCI_BindData(stmt, NULL, size, name, OCI_CDT_DATETIME,
03296                         code, OCI_BIND_OUTPUT, 0, NULL, 0);
03297 }
03298 
03299 /* --------------------------------------------------------------------------------------------- *
03300  * OCI_RegisterTimestamp
03301  * --------------------------------------------------------------------------------------------- */
03302 
03303 boolean OCI_API OCI_RegisterTimestamp
03304 (
03305     OCI_Statement *stmt,
03306     const mtext   *name,
03307     unsigned int   type
03308 )
03309 {
03310     int code    = 0;
03311     boolean res = FALSE;
03312 
03313     OCI_CHECK_REGISTER_CALL(stmt, name);
03314 
03315     OCI_CHECK_TIMESTAMP_ENABLED(stmt->con, FALSE);
03316 
03317     #if OCI_VERSION_COMPILE >= OCI_9_0
03318 
03319     /* map oracle internal type */
03320 
03321     if (type == OCI_TIMESTAMP_TZ)
03322         code = SQLT_TIMESTAMP_TZ;
03323     else if (type == OCI_TIMESTAMP_LTZ)
03324         code = SQLT_TIMESTAMP_LTZ;
03325     else
03326         code = SQLT_TIMESTAMP;
03327 
03328     res = OCI_BindData(stmt, NULL, sizeof(OCIDateTime *), name, OCI_CDT_TIMESTAMP,
03329                        code, OCI_BIND_OUTPUT, type, NULL, 0);
03330 
03331     #else
03332 
03333     OCI_NOT_USED(name);
03334     OCI_NOT_USED(type);
03335     OCI_NOT_USED(code);
03336 
03337     #endif
03338 
03339     return res;
03340 }
03341 
03342 /* --------------------------------------------------------------------------------------------- *
03343  * OCI_RegisterInterval
03344  * --------------------------------------------------------------------------------------------- */
03345 
03346 boolean OCI_API OCI_RegisterInterval
03347 (
03348     OCI_Statement *stmt,
03349     const mtext   *name,
03350     unsigned int   type
03351 )
03352 {
03353     unsigned int code = 0;
03354     boolean res       = FALSE;
03355 
03356     OCI_CHECK_REGISTER_CALL(stmt, name);
03357 
03358     OCI_CHECK_INTERVAL_ENABLED(stmt->con, FALSE);
03359 
03360     #if OCI_VERSION_COMPILE >= OCI_9_0
03361 
03362     /* map oracle internal type */
03363 
03364     if (type == OCI_INTERVAL_YM)
03365         code = SQLT_INTERVAL_YM;
03366     else if (type == OCI_INTERVAL_DS)
03367         code = SQLT_INTERVAL_DS;
03368 
03369     res = OCI_BindData(stmt, NULL, sizeof(OCIInterval *), name, OCI_CDT_INTERVAL,
03370                        code, OCI_BIND_OUTPUT, type, NULL, 0);
03371 
03372     #else
03373 
03374     OCI_NOT_USED(name);
03375     OCI_NOT_USED(type);
03376     OCI_NOT_USED(code);
03377 
03378     #endif
03379 
03380     return res;
03381 }
03382 
03383 /* --------------------------------------------------------------------------------------------- *
03384  * OCI_RegisterObject
03385  * --------------------------------------------------------------------------------------------- */
03386 
03387 boolean OCI_API OCI_RegisterObject
03388 (
03389     OCI_Statement *stmt,
03390     const mtext   *name,
03391     OCI_TypeInfo  *typinf
03392 )
03393 {
03394     OCI_CHECK_REGISTER_CALL(stmt, name);
03395 
03396     OCI_CHECK_PTR(OCI_IPC_TYPE_INFO, typinf, FALSE);
03397 
03398     return OCI_BindData(stmt, NULL, sizeof(OCIInterval *), name, OCI_CDT_OBJECT,
03399                         SQLT_NTY, OCI_BIND_OUTPUT, 0, typinf, 0);
03400 }
03401 
03402 /* --------------------------------------------------------------------------------------------- *
03403  * OCI_RegisterLob
03404  * --------------------------------------------------------------------------------------------- */
03405 
03406 boolean OCI_API OCI_RegisterLob
03407 (
03408     OCI_Statement *stmt,
03409     const mtext   *name,
03410     unsigned int   type
03411 )
03412 {
03413     unsigned int code = 0;
03414 
03415     OCI_CHECK_REGISTER_CALL(stmt, name);
03416 
03417     /* map oracle internal type */
03418 
03419     if (type == OCI_CLOB || type == OCI_NCLOB)
03420         code = SQLT_CLOB;
03421     else
03422         code = SQLT_BLOB;
03423 
03424     return OCI_BindData(stmt, NULL, sizeof(OCILobLocator*), name, OCI_CDT_LOB,
03425                         code, OCI_BIND_OUTPUT, type, NULL, 0);
03426 }
03427 
03428 /* --------------------------------------------------------------------------------------------- *
03429  * OCI_RegisterFile
03430  * --------------------------------------------------------------------------------------------- */
03431 
03432 boolean OCI_API OCI_RegisterFile
03433 (
03434     OCI_Statement *stmt,
03435     const mtext   *name,
03436     unsigned int   type
03437 )
03438 {
03439     unsigned int code;
03440 
03441     OCI_CHECK_REGISTER_CALL(stmt, name);
03442 
03443     /* map oracle internal type */
03444 
03445     if (type == OCI_CFILE)
03446         code = SQLT_CFILE;
03447     else
03448         code = SQLT_BFILE;
03449 
03450     return OCI_BindData(stmt, NULL, sizeof(OCILobLocator*), name, OCI_CDT_FILE,
03451                         code, OCI_BIND_OUTPUT, type, NULL, 0);
03452 }
03453 
03454 /* --------------------------------------------------------------------------------------------- *
03455  * OCI_RegisterRef
03456  * --------------------------------------------------------------------------------------------- */
03457 
03458 boolean OCI_API OCI_RegisterRef
03459 (
03460     OCI_Statement *stmt,
03461     const mtext   *name,
03462     OCI_TypeInfo  *typinf
03463 )
03464 {
03465     OCI_CHECK_REGISTER_CALL(stmt, name);
03466 
03467     OCI_CHECK_PTR(OCI_IPC_TYPE_INFO, typinf, FALSE);
03468 
03469     return OCI_BindData(stmt, NULL, sizeof(OCIRef *), name, OCI_CDT_REF,
03470                         SQLT_REF, OCI_BIND_OUTPUT, 0, typinf, 0);
03471 }
03472 
03473 /* --------------------------------------------------------------------------------------------- *
03474  * OCI_GetStatementType
03475  * --------------------------------------------------------------------------------------------- */
03476 
03477 unsigned int OCI_API OCI_GetStatementType
03478 (
03479     OCI_Statement *stmt
03480 )
03481 {
03482     OCI_CHECK_PTR(OCI_IPC_STATEMENT, stmt, OCI_UNKNOWN);
03483 
03484     OCI_RESULT(TRUE);
03485 
03486     return stmt->type;
03487 }
03488 
03489 /* --------------------------------------------------------------------------------------------- *
03490  * OCI_SetFetchMode
03491  * --------------------------------------------------------------------------------------------- */
03492 
03493 boolean OCI_API OCI_SetFetchMode
03494 (
03495     OCI_Statement *stmt,
03496     unsigned int   mode
03497 )
03498 {
03499     OCI_CHECK_PTR(OCI_IPC_STATEMENT, stmt, FALSE);
03500 
03501     OCI_CHECK_SCROLLABLE_CURSOR_ENABLED(stmt->con, FALSE);
03502 
03503     stmt->exec_mode = mode;
03504 
03505     OCI_RESULT(TRUE);
03506 
03507     return TRUE;
03508 }
03509 
03510 /* --------------------------------------------------------------------------------------------- *
03511  * OCI_GetFetchMode
03512  * --------------------------------------------------------------------------------------------- */
03513 
03514 unsigned int OCI_API OCI_GetFetchMode
03515 (
03516     OCI_Statement *stmt
03517 )
03518 {
03519     OCI_CHECK_PTR(OCI_IPC_STATEMENT, stmt, OCI_UNKNOWN);
03520 
03521     OCI_CHECK_SCROLLABLE_CURSOR_ENABLED(stmt->con, OCI_UNKNOWN);
03522 
03523     OCI_RESULT(TRUE);
03524 
03525     return stmt->exec_mode;
03526 }
03527 
03528 /* --------------------------------------------------------------------------------------------- *
03529  * OCI_SetBindMode
03530  * --------------------------------------------------------------------------------------------- */
03531 
03532 boolean OCI_API OCI_SetBindMode
03533 (
03534     OCI_Statement *stmt,
03535     unsigned int   mode
03536 )
03537 {
03538     OCI_CHECK_PTR(OCI_IPC_STATEMENT, stmt, FALSE);
03539 
03540     stmt->bind_mode = mode;
03541 
03542     OCI_RESULT(TRUE);
03543 
03544     return TRUE;
03545 }
03546 
03547 /* --------------------------------------------------------------------------------------------- *
03548  * OCI_GetBindMode
03549  * --------------------------------------------------------------------------------------------- */
03550 
03551 unsigned int OCI_API OCI_GetBindMode
03552 (
03553     OCI_Statement *stmt
03554 )
03555 {
03556     OCI_CHECK_PTR(OCI_IPC_STATEMENT, stmt, OCI_UNKNOWN);
03557 
03558     OCI_RESULT(TRUE);
03559 
03560     return stmt->bind_mode;
03561 }
03562 
03563 /* --------------------------------------------------------------------------------------------- *
03564  * OCI_SetBindAllocation
03565  * --------------------------------------------------------------------------------------------- */
03566 
03567 boolean OCI_API OCI_SetBindAllocation
03568 (
03569     OCI_Statement *stmt,
03570     unsigned int   mode
03571 )
03572 {
03573     OCI_CHECK_PTR(OCI_IPC_STATEMENT, stmt, FALSE);
03574 
03575     stmt->bind_alloc_mode = mode;
03576 
03577     OCI_RESULT(TRUE);
03578 
03579     return TRUE;
03580 }
03581 
03582 /* --------------------------------------------------------------------------------------------- *
03583  * OCI_GetBindAllocation
03584  * --------------------------------------------------------------------------------------------- */
03585 
03586 unsigned int OCI_API OCI_GetBindAllocation
03587 (
03588     OCI_Statement *stmt
03589 )
03590 {
03591     OCI_CHECK_PTR(OCI_IPC_STATEMENT, stmt, OCI_UNKNOWN);
03592 
03593     OCI_RESULT(TRUE);
03594 
03595     return stmt->bind_alloc_mode;
03596 }
03597 
03598 /* --------------------------------------------------------------------------------------------- *
03599  * OCI_SetFetchSize
03600  * --------------------------------------------------------------------------------------------- */
03601 
03602 boolean OCI_API OCI_SetFetchSize
03603 (
03604     OCI_Statement *stmt,
03605     unsigned int   size
03606 )
03607 {
03608     OCI_CHECK_PTR(OCI_IPC_STATEMENT, stmt, FALSE);
03609 
03610     OCI_CHECK_MIN(stmt->con, stmt, size, 1, FALSE);
03611 
03612     stmt->fetch_size = size;
03613 
03614     OCI_RESULT(TRUE);
03615 
03616     return TRUE;
03617 }
03618 
03619 /* --------------------------------------------------------------------------------------------- *
03620  * OCI_GetFetchSize
03621  * --------------------------------------------------------------------------------------------- */
03622 
03623 unsigned int OCI_API OCI_GetFetchSize
03624 (
03625     OCI_Statement *stmt
03626 )
03627 {
03628     OCI_CHECK_PTR(OCI_IPC_STATEMENT, stmt, 0);
03629 
03630     OCI_RESULT(TRUE);
03631 
03632     return stmt->fetch_size;
03633 }
03634 
03635 /* --------------------------------------------------------------------------------------------- *
03636  * OCI_SetPrefetchSize
03637  * --------------------------------------------------------------------------------------------- */
03638 
03639 boolean OCI_API OCI_SetPrefetchSize
03640 (
03641     OCI_Statement *stmt,
03642     unsigned int   size
03643 )
03644 {
03645     boolean res = TRUE;
03646 
03647     OCI_CHECK_PTR(OCI_IPC_STATEMENT, stmt,  FALSE);
03648 
03649     OCI_CALL1
03650     (
03651         res, stmt->con, stmt,
03652 
03653         OCIAttrSet((dvoid *) stmt->stmt, (ub4) OCI_HTYPE_STMT,
03654                    (dvoid *) &stmt->prefetch_size,
03655                    (ub4) sizeof(stmt->prefetch_size),
03656                    (ub4) OCI_ATTR_PREFETCH_ROWS, stmt->con->err)
03657     )
03658 
03659     if (res == TRUE)
03660         stmt->prefetch_size = size;
03661 
03662     OCI_RESULT(res);
03663 
03664     return res;
03665 }
03666 
03667 /* --------------------------------------------------------------------------------------------- *
03668  * OCI_GetPrefetchSize
03669  * --------------------------------------------------------------------------------------------- */
03670 
03671 unsigned int OCI_API OCI_GetPrefetchSize
03672 (
03673     OCI_Statement *stmt
03674 )
03675 {
03676     OCI_CHECK_PTR(OCI_IPC_STATEMENT, stmt, 0);
03677 
03678     OCI_RESULT(TRUE);
03679 
03680     return stmt->prefetch_size;
03681 }
03682 
03683 /* --------------------------------------------------------------------------------------------- *
03684  * OCI_SetPrefetchMemory
03685  * --------------------------------------------------------------------------------------------- */
03686 
03687 boolean OCI_API OCI_SetPrefetchMemory
03688 (
03689     OCI_Statement *stmt,
03690     unsigned int   size
03691 )
03692 {
03693     boolean res = TRUE;
03694 
03695     OCI_CHECK_PTR(OCI_IPC_STATEMENT, stmt,  FALSE);
03696 
03697     OCI_CALL1
03698     (
03699         res, stmt->con, stmt,
03700 
03701         OCIAttrSet((dvoid *) stmt->stmt, (ub4) OCI_HTYPE_STMT,
03702                    (dvoid *) &stmt->prefetch_mem,
03703                    (ub4) sizeof(stmt->prefetch_mem),
03704                    (ub4) OCI_ATTR_PREFETCH_MEMORY, stmt->con->err)
03705     )
03706 
03707     if (res == TRUE)
03708         stmt->prefetch_mem = size;
03709 
03710     OCI_RESULT(res);
03711 
03712     return res;
03713 }
03714 
03715 /* --------------------------------------------------------------------------------------------- *
03716  * OCI_GetPrefetchMemory
03717  * --------------------------------------------------------------------------------------------- */
03718 
03719 unsigned int OCI_API OCI_GetPrefetchMemory
03720 (
03721     OCI_Statement *stmt
03722 )
03723 {
03724     OCI_CHECK_PTR(OCI_IPC_STATEMENT, stmt, 0);
03725 
03726     OCI_RESULT(TRUE);
03727 
03728     return stmt->prefetch_mem;
03729 }
03730 
03731 /* --------------------------------------------------------------------------------------------- *
03732  * OCI_SetLongMaxSize
03733  * --------------------------------------------------------------------------------------------- */
03734 
03735 boolean OCI_API OCI_SetLongMaxSize
03736 (
03737     OCI_Statement *stmt,
03738     unsigned int   size
03739 )
03740 {
03741     OCI_CHECK_PTR(OCI_IPC_STATEMENT, stmt,  FALSE);
03742 
03743     OCI_CHECK_MIN(stmt->con, stmt, size, 1, FALSE);
03744 
03745     stmt->long_size = size;
03746 
03747     OCI_RESULT(TRUE);
03748 
03749     return TRUE;
03750 }
03751 
03752 /* --------------------------------------------------------------------------------------------- *
03753  * OCI_GetLongMaxSize
03754  * --------------------------------------------------------------------------------------------- */
03755 
03756 unsigned int OCI_API OCI_GetLongMaxSize
03757 (
03758     OCI_Statement *stmt
03759 )
03760 {
03761     OCI_CHECK_PTR(OCI_IPC_STATEMENT, stmt, 0);
03762 
03763     OCI_RESULT(TRUE);
03764 
03765     return stmt->long_size;
03766 }
03767 
03768 /* --------------------------------------------------------------------------------------------- *
03769  * OCI_SetLongMode
03770  * --------------------------------------------------------------------------------------------- */
03771 
03772 boolean OCI_API OCI_SetLongMode
03773 (
03774     OCI_Statement *stmt,
03775     unsigned int   mode
03776 )
03777 {
03778     OCI_CHECK_PTR(OCI_IPC_STATEMENT, stmt, FALSE);
03779 
03780     stmt->long_mode = (ub1) mode;
03781 
03782     OCI_RESULT(TRUE);
03783 
03784     return TRUE;
03785 }
03786 
03787 /* --------------------------------------------------------------------------------------------- *
03788  * OCI_GetLongMode
03789  * --------------------------------------------------------------------------------------------- */
03790 
03791 unsigned int OCI_API OCI_GetLongMode
03792 (
03793     OCI_Statement *stmt
03794 )
03795 {
03796     OCI_CHECK_PTR(OCI_IPC_STATEMENT, stmt, OCI_UNKNOWN);
03797 
03798     OCI_RESULT(TRUE);
03799 
03800     return stmt->long_mode;
03801 }
03802 
03803 /* --------------------------------------------------------------------------------------------- *
03804  * OCI_StatementGetConnection
03805  * --------------------------------------------------------------------------------------------- */
03806 
03807 OCI_Connection * OCI_API OCI_StatementGetConnection
03808 (
03809     OCI_Statement *stmt
03810 )
03811 {
03812     OCI_CHECK_PTR(OCI_IPC_STATEMENT, stmt, NULL);
03813 
03814     OCI_RESULT(TRUE);
03815 
03816     return stmt->con;
03817 }
03818 
03819 /* --------------------------------------------------------------------------------------------- *
03820  * OCI_GetSql
03821  * --------------------------------------------------------------------------------------------- */
03822 
03823 const mtext * OCI_API OCI_GetSql
03824 (
03825     OCI_Statement *stmt
03826 )
03827 {
03828     OCI_CHECK_PTR(OCI_IPC_STATEMENT, stmt, NULL);
03829 
03830     OCI_RESULT(TRUE);
03831 
03832     return stmt->sql;
03833 }
03834 
03835 /* --------------------------------------------------------------------------------------------- *
03836  * OCI_GetSqlErrorPos
03837  * --------------------------------------------------------------------------------------------- */
03838 
03839 unsigned int OCI_API OCI_GetSqlErrorPos
03840 (
03841     OCI_Statement *stmt
03842 )
03843 {
03844     OCI_CHECK_PTR(OCI_IPC_STATEMENT, stmt, 0);
03845 
03846     OCI_RESULT(TRUE);
03847 
03848     return stmt->err_pos;
03849 }
03850 
03851 /* --------------------------------------------------------------------------------------------- *
03852  * OCI_GetAffecteddRows
03853  * --------------------------------------------------------------------------------------------- */
03854 
03855 unsigned int OCI_API OCI_GetAffectedRows
03856 (
03857     OCI_Statement *stmt
03858 )
03859 {
03860     boolean res = TRUE;
03861     ub4 count   = 0;
03862 
03863     OCI_CHECK_PTR(OCI_IPC_STATEMENT, stmt,  0);
03864 
03865     OCI_CALL1
03866     (
03867         res, stmt->con, stmt,
03868 
03869         OCIAttrGet((dvoid *) stmt->stmt, (ub4) OCI_HTYPE_STMT,
03870                    (void *) &count, (ub4 *) NULL, (ub4) OCI_ATTR_ROW_COUNT,
03871                    stmt->con->err)
03872     )
03873 
03874     OCI_RESULT(res);
03875 
03876     return count;
03877 }
03878 
03879 /* --------------------------------------------------------------------------------------------- *
03880  * OCI_GetBindCount
03881  * --------------------------------------------------------------------------------------------- */
03882 
03883 unsigned int OCI_API OCI_GetBindCount
03884 (
03885     OCI_Statement *stmt
03886 )
03887 {
03888     OCI_CHECK_PTR(OCI_IPC_STATEMENT, stmt, 0);
03889 
03890     OCI_RESULT(TRUE);
03891 
03892     return (unsigned int) stmt->nb_ubinds;
03893 }
03894 
03895 /* --------------------------------------------------------------------------------------------- *
03896  * OCI_GetBind
03897  * --------------------------------------------------------------------------------------------- */
03898 
03899 OCI_Bind * OCI_API OCI_GetBind
03900 (
03901     OCI_Statement *stmt,
03902     unsigned int   index
03903 )
03904 {
03905     OCI_CHECK_PTR(OCI_IPC_STATEMENT, stmt, NULL);
03906     OCI_CHECK_BOUND(stmt->con, index, 1, stmt->nb_ubinds, NULL);
03907 
03908     OCI_RESULT(TRUE);
03909 
03910     return stmt->ubinds[index-1];
03911 }
03912 
03913 /* --------------------------------------------------------------------------------------------- *
03914  * OCI_GetBind2
03915  * --------------------------------------------------------------------------------------------- */
03916 
03917 OCI_Bind * OCI_API OCI_GetBind2
03918 (
03919     OCI_Statement *stmt,
03920     const mtext   *name
03921 )
03922 {
03923     OCI_Bind *bnd = NULL;
03924     int index     = -1;
03925 
03926     OCI_CHECK_PTR(OCI_IPC_STATEMENT, stmt, NULL);
03927     OCI_CHECK_PTR(OCI_IPC_STRING, name, NULL);
03928 
03929     index =  OCI_BindGetIndex(stmt, name);
03930 
03931     if (index > 0)
03932         bnd = stmt->ubinds[index-1];
03933 
03934     OCI_RESULT(bnd != NULL);
03935 
03936     return bnd;
03937 }
03938 
03939 /* --------------------------------------------------------------------------------------------- *
03940  * OCI_GetSQLCommand
03941  * --------------------------------------------------------------------------------------------- */
03942 
03943 unsigned int OCI_API OCI_GetSQLCommand
03944 (
03945     OCI_Statement *stmt
03946 )
03947 {
03948     boolean res = TRUE;
03949     ub2 code    = OCI_UNKNOWN;
03950 
03951     OCI_CHECK_PTR(OCI_IPC_STATEMENT, stmt, OCI_UNKNOWN);
03952 
03953     OCI_CALL1
03954     (
03955         res, stmt->con, stmt,
03956 
03957         OCIAttrGet((dvoid *) stmt->stmt, (ub4) OCI_HTYPE_STMT,
03958                    (dvoid *) &code, (ub4 *) NULL,
03959                    (ub4) OCI_ATTR_SQLFNCODE, stmt->con->err)
03960     )
03961 
03962     OCI_RESULT(res);
03963 
03964     return (unsigned int) code;
03965 }
03966 
03967 /* --------------------------------------------------------------------------------------------- *
03968  * OCI_GetSQLVerb
03969  * --------------------------------------------------------------------------------------------- */
03970 
03971 const mtext * OCI_API OCI_GetSQLVerb
03972 (
03973     OCI_Statement *stmt
03974 )
03975 {
03976     mtext * desc      = NULL;
03977     unsigned int code = OCI_UNKNOWN;
03978 
03979     int i;
03980 
03981     code = OCI_GetSQLCommand(stmt);
03982 
03983     if (code != OCI_UNKNOWN)
03984     {
03985         for (i = 0; i < OCI_SQLCMD_COUNT; i++)
03986         {
03987             if (code == SQLCmds[i].code)
03988             {
03989                 desc = SQLCmds[i].verb;
03990                 break;
03991             }
03992         }
03993     }
03994 
03995     return desc;
03996 }
03997 
03998 /* --------------------------------------------------------------------------------------------- *
03999  * OCI_GetBatchError
04000  * --------------------------------------------------------------------------------------------- */
04001 
04002 OCI_Error * OCI_API OCI_GetBatchError
04003 (
04004     OCI_Statement *stmt
04005 )
04006 {
04007     OCI_Error *err = NULL;
04008 
04009     OCI_CHECK_PTR(OCI_IPC_STATEMENT, stmt, NULL);
04010 
04011     if (stmt->batch != NULL)
04012     {
04013         if (stmt->batch->cur < stmt->batch->count)
04014         {
04015             err = &stmt->batch->errs[stmt->batch->cur++];
04016         }
04017     }
04018 
04019     OCI_RESULT(TRUE);
04020 
04021     return err;
04022 }
04023 
04024 /* --------------------------------------------------------------------------------------------- *
04025  * OCI_GetBatchErrorCount
04026  * --------------------------------------------------------------------------------------------- */
04027 
04028 unsigned int OCI_API OCI_GetBatchErrorCount
04029 (
04030     OCI_Statement *stmt
04031 )
04032 {
04033     unsigned int count = 0;
04034 
04035     OCI_CHECK_PTR(OCI_IPC_STATEMENT, stmt, 0);
04036 
04037     if (stmt->batch != NULL)
04038     {
04039         count = stmt->batch->count;
04040     }
04041 
04042     OCI_RESULT(TRUE);
04043 
04044     return 0;
04045 }

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