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

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