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

D:/Perso/dev/ocilib/ocilib/src/dirpath.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: dirpath.c, v 3.8.0 2010-10-24 21:53 Vincent Rogier $
00033  * --------------------------------------------------------------------------------------------- */
00034 
00035 #include "ocilib_internal.h"
00036 
00037 /* ********************************************************************************************* *
00038  *                            PUBLIC FUNCTIONS
00039  * ********************************************************************************************* */
00040 
00041 /* --------------------------------------------------------------------------------------------- *
00042  * OCI_DirPathCreate
00043  * --------------------------------------------------------------------------------------------- */
00044 
00045 OCI_DirPath * OCI_API OCI_DirPathCreate
00046 (
00047     OCI_TypeInfo *typinf,
00048     const mtext  *partition,
00049     unsigned int  nb_cols,
00050     unsigned int  nb_rows
00051 )
00052 {
00053     OCI_DirPath *dp = NULL;
00054 
00055     void *ostr = NULL;
00056     int osize  = -1;
00057 
00058     boolean res = TRUE;
00059 
00060     OCI_CHECK_PTR(OCI_IPC_TYPE_INFO, typinf, NULL);
00061 
00062     OCI_CHECK_COMPAT(typinf->con, typinf->type != OCI_TIF_TYPE, NULL);
00063     OCI_CHECK_BOUND(typinf->con, nb_cols, 1, typinf->nb_cols, NULL);
00064 
00065     /* allocate direct path structure */
00066 
00067     dp = (OCI_DirPath *) OCI_MemAlloc(OCI_IPC_DIRPATH, sizeof(*dp),
00068                                       (size_t) 1, TRUE);
00069 
00070     if (dp != NULL)
00071     {
00072         dp->con      = typinf->con;
00073         dp->status   = OCI_DPS_NOT_PREPARED;
00074         dp->typinf   = typinf;
00075         dp->nb_rows  = (ub2) nb_rows;
00076         dp->nb_cols  = (ub2) nb_cols;
00077         dp->nb_cur   = (ub2) dp->nb_rows;
00078         dp->err_col  = 0;
00079         dp->err_row  = 0;
00080         dp->nb_prcsd = 0;
00081 
00082         /* allocates direct context handle */
00083 
00084         if (res == TRUE)
00085         {
00086             res = (OCI_SUCCESS == OCI_HandleAlloc((dvoid *) OCILib.env,
00087                                                   (dvoid **) (void *) &dp->ctx,
00088                                                   (ub4) OCI_HTYPE_DIRPATH_CTX,
00089                                                   (size_t) 0, (dvoid **) NULL));
00090         }
00091 
00092         /* set table name attribute */
00093 
00094         if (res == TRUE)
00095         {
00096             osize = -1;
00097             ostr  = OCI_GetInputMetaString(dp->typinf->name, &osize);
00098 
00099             OCI_CALL2
00100             (
00101                 res, dp->con,
00102 
00103                 OCIAttrSet((dvoid *) dp->ctx, (ub4) OCI_HTYPE_DIRPATH_CTX,
00104                            (dvoid *) ostr, (ub4) osize,
00105                            (ub4) OCI_ATTR_NAME, dp->con->err)
00106             )
00107 
00108             OCI_ReleaseMetaString(ostr);
00109         }
00110 
00111         /* set schema name attribute */
00112 
00113         if ((res == TRUE) && (dp->typinf->schema != NULL) && (dp->typinf->schema[0] != 0))
00114         {
00115             osize = -1;
00116             ostr  = OCI_GetInputMetaString(dp->typinf->schema, &osize);
00117 
00118             OCI_CALL2
00119             (
00120                 res, dp->con,
00121 
00122                 OCIAttrSet((dvoid *) dp->ctx, (ub4) OCI_HTYPE_DIRPATH_CTX,
00123                            (dvoid *) ostr, (ub4) osize,
00124                            (ub4) OCI_ATTR_SCHEMA_NAME, dp->con->err)
00125             )
00126 
00127             OCI_ReleaseMetaString(ostr);
00128         }
00129 
00130         /* set partition name attribute */
00131 
00132         if ((res == TRUE) && (partition != NULL) && (partition[0] != 0))
00133         {
00134             osize = -1;
00135             ostr  = OCI_GetInputMetaString(partition, &osize);
00136 
00137             OCI_CALL2
00138             (
00139                 res, dp->con,
00140 
00141                 OCIAttrSet((dvoid *) dp->ctx, (ub4) OCI_HTYPE_DIRPATH_CTX,
00142                            (dvoid *) ostr, (ub4) osize,
00143                            (ub4) OCI_ATTR_SUB_NAME, dp->con->err)
00144             )
00145 
00146             OCI_ReleaseMetaString(ostr);
00147         }
00148 
00149         if (OCILib.version_runtime >= OCI_9_0)
00150         {
00151             ub4 num_rows = dp->nb_rows;
00152 
00153             /* set array size attribute */
00154 
00155             OCI_CALL2
00156             (
00157                 res, dp->con,
00158 
00159                 OCIAttrSet((dvoid *) dp->ctx, (ub4) OCI_HTYPE_DIRPATH_CTX,
00160                            (dvoid *) &num_rows, (ub4) sizeof(num_rows),
00161                            (ub4) OCI_ATTR_NUM_ROWS, dp->con->err)
00162             )
00163         }
00164 
00165         /* set columns count attribute */
00166 
00167         OCI_CALL2
00168         (
00169             res, dp->con,
00170 
00171             OCIAttrSet((dvoid *) dp->ctx, (ub4) OCI_HTYPE_DIRPATH_CTX,
00172                        (dvoid *) &dp->nb_cols, (ub4) sizeof(dp->nb_cols),
00173                        (ub4) OCI_ATTR_NUM_COLS, dp->con->err)
00174         )
00175 
00176         /* allocating the column array */
00177 
00178         if (res == TRUE)
00179         {
00180             dp->cols = (void *) OCI_MemAlloc(OCI_IPC_DP_COL_ARRAY,
00181                                              sizeof(OCI_DirPathColumn),
00182                                              (size_t) dp->nb_cols, TRUE);
00183 
00184             res = (dp->cols != NULL);
00185         }
00186     }
00187     else
00188         res = FALSE;
00189 
00190     /* handle errors */
00191 
00192     if (res == FALSE)
00193     {
00194         OCI_DirPathFree(dp);
00195         dp = NULL;
00196     }
00197 
00198     OCI_RESULT(res);
00199 
00200     return dp;
00201 }
00202 
00203 /* --------------------------------------------------------------------------------------------- *
00204  * OCI_DirPathFree
00205  * --------------------------------------------------------------------------------------------- */
00206 
00207 boolean OCI_API OCI_DirPathFree
00208 (
00209     OCI_DirPath *dp
00210 )
00211 {
00212     ub2 i;
00213 
00214     OCI_CHECK_PTR(OCI_IPC_DIRPATH, dp, FALSE);
00215 
00216     for (i = 0; i < dp->nb_cols; i++)
00217     {
00218         OCI_FREE(dp->cols[i].data);
00219         OCI_FREE(dp->cols[i].lens);
00220         OCI_FREE(dp->cols[i].flags);
00221         OCI_FREE(dp->cols[i].format);
00222     }
00223 
00224     OCI_FREE(dp->cols);
00225 
00226     OCI_HandleFree(dp->strm, OCI_HTYPE_DIRPATH_STREAM);
00227     OCI_HandleFree(dp->arr,  OCI_HTYPE_DIRPATH_COLUMN_ARRAY);
00228     OCI_HandleFree(dp->ctx,  OCI_HTYPE_DIRPATH_CTX);
00229 
00230     OCI_FREE(dp);
00231 
00232     OCI_RESULT(TRUE);
00233 
00234     return TRUE;
00235 }
00236 
00237 /* --------------------------------------------------------------------------------------------- *
00238  * OCI_DirPathSetColumn
00239  * --------------------------------------------------------------------------------------------- */
00240 
00241 boolean OCI_API OCI_DirPathSetColumn
00242 (
00243     OCI_DirPath *dp,
00244     unsigned int index,
00245     const mtext *name,
00246     unsigned int maxsize,
00247     const mtext *format
00248 )
00249 {
00250     OCI_DirPathColumn *dpcol = NULL;
00251     OCI_Column *col          = NULL;
00252     OCIParam *hattr          = NULL;
00253     OCIParam *hlist          = NULL;
00254     void *ostr               = NULL;
00255     int osize                = -1;
00256     boolean res              = TRUE;
00257     ub2 i;
00258 
00259     OCI_CHECK_PTR(OCI_IPC_DIRPATH, dp, FALSE);
00260     OCI_CHECK_DIRPATH_STATUS(dp, OCI_DPS_NOT_PREPARED, FALSE);
00261     OCI_CHECK_PTR(OCI_IPC_STRING, name, FALSE);
00262     OCI_CHECK_BOUND(dp->con, index, 1, dp->nb_cols, FALSE);
00263 
00264     /* check if column exists */
00265 
00266     for (i = 0; i < dp->typinf->nb_cols; i++)
00267     {
00268         if (mtscasecmp(name, dp->typinf->cols[i].name) == 0)
00269         {
00270             break;
00271         }
00272     }
00273 
00274     /* check if column was found */
00275 
00276     if (i >= dp->typinf->nb_cols)
00277     {
00278         OCI_ExceptionDirPathColNotFound(dp, name, dp->typinf->name);
00279 
00280         res = FALSE;
00281     }
00282 
00283     /* set column information */
00284 
00285     if (res == TRUE)
00286     {
00287         col   = &dp->typinf->cols[i];
00288         dpcol = &dp->cols[index-1];
00289 
00290         /* default column attributes */
00291 
00292         dpcol->maxsize     = (ub2) maxsize;
00293         dpcol->bufsize     = (ub2) maxsize + 1;
00294         dpcol->sqlcode     = SQLT_CHR;
00295         dpcol->type        = OCI_DDT_TEXT;
00296         dpcol->index       = i;
00297         dpcol->format_size = 0;
00298 
00299         switch (col->type)
00300         {
00301         case OCI_CDT_TEXT:
00302 
00303             dpcol->maxsize *= sizeof(dtext);
00304             dpcol->bufsize *= sizeof(dtext);
00305 
00306             if (OCILib.nls_utf8 == TRUE)
00307             {
00308                 dpcol->bufsize *= UTF8_BYTES_PER_CHAR;
00309             }
00310 
00311             break;
00312 
00313         case OCI_CDT_NUMERIC:
00314 
00315             if ((format != NULL) && (format[0] != 0))
00316             {
00317                 dpcol->format      = mtsdup(format);
00318                 dpcol->format_size = (ub4) mtslen(format);
00319                 dpcol->type        = OCI_DDT_NUMBER;
00320                 dpcol->sqlcode     = SQLT_NUM;
00321                 dpcol->bufsize     = sizeof(OCINumber);
00322                 dpcol->maxsize     = sizeof(OCINumber);
00323             }
00324             else
00325             {
00326                 dpcol->type = OCI_DDT_OTHERS;
00327             }
00328 
00329             break;
00330 
00331         case OCI_CDT_DATETIME:
00332         case OCI_CDT_TIMESTAMP:
00333         case OCI_CDT_INTERVAL:
00334 
00335             dpcol->type = OCI_DDT_OTHERS;
00336 
00337             if ((format != NULL) && (format[0] != 0))
00338             {
00339                 dpcol->format      = mtsdup(format);
00340                 dpcol->format_size = (ub4) mtslen(format);
00341                 dpcol->maxsize     = (ub2) dpcol->format_size;
00342                 dpcol->bufsize    *= sizeof(dtext);
00343             }
00344 
00345             break;
00346 
00347         case OCI_CDT_LOB:
00348 
00349             if (col->subtype == OCI_BLOB)
00350             {
00351                 dpcol->type    = OCI_DDT_BINARY;
00352                 dpcol->sqlcode = SQLT_BIN;
00353             }
00354 
00355             break;
00356 
00357         case OCI_CDT_LONG:
00358 
00359             if (col->subtype == OCI_BLONG)
00360             {
00361                 dpcol->type    = OCI_DDT_BINARY;
00362                 dpcol->sqlcode = SQLT_BIN;
00363             }
00364 
00365             break;
00366 
00367         case OCI_CDT_RAW:
00368 
00369             dpcol->type    = OCI_DDT_BINARY;
00370             dpcol->sqlcode = SQLT_BIN;
00371 
00372             break;
00373 
00374         default:
00375 
00376             res = FALSE;
00377             OCI_ExceptionDatatypeNotSupported(dp->con, NULL, col->ocode);
00378 
00379             break;
00380         }
00381     }
00382 
00383     /* if supported datatype, set direct path column attributes */
00384 
00385     if (res == TRUE)
00386     {
00387         /* get column parameter list handle */
00388 
00389         OCI_CALL2
00390         (
00391             res, dp->con,
00392 
00393             OCIAttrGet(dp->ctx, OCI_HTYPE_DIRPATH_CTX, &hlist,
00394                        NULL, OCI_ATTR_LIST_COLUMNS, dp->con->err)
00395         )
00396 
00397         /* get colum attribute handle */
00398 
00399         OCI_CALL2
00400         (
00401             res, dp->con,
00402 
00403             OCIParamGet((dvoid *) hlist, OCI_DTYPE_PARAM, dp->con->err,
00404                         (dvoid** ) (dvoid *) &hattr, (ub4) index)
00405         )
00406 
00407         /* set column name */
00408 
00409         if (res == TRUE)
00410         {
00411             osize = -1;
00412             ostr  = OCI_GetInputMetaString(name, &osize);
00413 
00414             OCI_CALL2
00415             (
00416                 res, dp->con,
00417 
00418                 OCIAttrSet((dvoid *) hattr, (ub4) OCI_DTYPE_PARAM,
00419                            (dvoid *) ostr, (ub4) osize,
00420                            (ub4) OCI_ATTR_NAME, dp->con->err)
00421             )
00422 
00423             OCI_ReleaseMetaString(ostr);
00424         }
00425 
00426         /* set column type */
00427 
00428         OCI_CALL2
00429         (
00430             res, dp->con,
00431 
00432             OCIAttrSet((dvoid *) hattr, (ub4) OCI_DTYPE_PARAM,
00433                        (dvoid *) &dpcol->sqlcode, sizeof(dpcol->sqlcode),
00434                        (ub4) OCI_ATTR_DATA_TYPE, dp->con->err)
00435         )
00436 
00437         /* set column size */
00438 
00439         OCI_CALL2
00440         (
00441             res, dp->con,
00442 
00443             OCIAttrSet((dvoid *) hattr, (ub4) OCI_DTYPE_PARAM,
00444                        (dvoid *) &dpcol->maxsize, sizeof(dpcol->maxsize),
00445                        (ub4) OCI_ATTR_DATA_SIZE, dp->con->err)
00446         )
00447 
00448         /* set column precision */
00449 
00450         if (col->prec != 0)
00451         {
00452             OCI_CALL2
00453             (
00454                 res, dp->con,
00455 
00456                 OCIAttrSet((dvoid *) hattr, (ub4) OCI_DTYPE_PARAM,
00457                            (dvoid *) &col->prec, sizeof(col->prec),
00458                            (ub4) OCI_ATTR_PRECISION, dp->con->err)
00459             )
00460         }
00461 
00462         /* set column scale */
00463 
00464         if (col->scale != 0)
00465         {
00466             OCI_CALL2
00467             (
00468                 res, dp->con,
00469 
00470                 OCIAttrSet((dvoid *) hattr, (ub4) OCI_DTYPE_PARAM,
00471                            (dvoid *) &col->scale, sizeof(col->scale),
00472                            (ub4) OCI_ATTR_SCALE, dp->con->err)
00473             )
00474         }
00475 
00476         /* set column date/time format attribute */
00477 
00478         if ((res == TRUE) && (dpcol->type != OCI_DDT_NUMBER) &&
00479             (dpcol->format != NULL) && (dpcol->format[0] != 0))
00480         {
00481             osize = -1;
00482             ostr  = OCI_GetInputMetaString(dpcol->format, &osize);
00483 
00484             OCI_CALL2
00485             (
00486                 res, dp->con,
00487 
00488                 OCIAttrSet((dvoid *) hattr, (ub4) OCI_DTYPE_PARAM,
00489                            (dvoid *) ostr, (ub4) osize,
00490                            (ub4) OCI_ATTR_DATEFORMAT, dp->con->err)
00491             )
00492 
00493             OCI_ReleaseMetaString(ostr);
00494         }
00495 
00496         #ifdef OCI_CHARSET_WIDE
00497 
00498         /* setup Unicode mode for Unicode user data */
00499 
00500         if (dpcol->type == OCI_DDT_TEXT)
00501         {
00502             ub2 csid = OCI_UTF16ID;
00503 
00504             OCI_CALL2
00505             (
00506                 res, dp->con,
00507 
00508                 OCIAttrSet((dvoid *) hattr, (ub4) OCI_DTYPE_PARAM,
00509                            (dvoid *) &csid,  (ub4) sizeof(csid),
00510                            (ub4) OCI_ATTR_CHARSET_ID,  dp->con->err)
00511             )
00512         }
00513 
00514         #endif
00515 
00516         /* free param handle */
00517 
00518         OCIDescriptorFree(hattr, OCI_DTYPE_PARAM);
00519     }
00520 
00521     OCI_RESULT(res);
00522 
00523     return res;
00524 }
00525 
00526 /* --------------------------------------------------------------------------------------------- *
00527  * OCI_DirPathPrepare
00528  * --------------------------------------------------------------------------------------------- */
00529 
00530 boolean OCI_API OCI_DirPathPrepare
00531 (
00532     OCI_DirPath *dp
00533 )
00534 {
00535     boolean res = TRUE;
00536     ub2 i;
00537 
00538     OCI_CHECK_PTR(OCI_IPC_DIRPATH, dp, FALSE);
00539     OCI_CHECK_DIRPATH_STATUS(dp, OCI_DPS_NOT_PREPARED, FALSE);
00540 
00541     /* prepare direct path operation */
00542 
00543     OCI_CALL2
00544     (
00545         res, dp->con,
00546 
00547         OCIDirPathPrepare(dp->ctx, dp->con->cxt, dp->con->err)
00548     )
00549 
00550     /* allocate column array handle */
00551 
00552     if (res == TRUE)
00553     {
00554         res = (OCI_SUCCESS == OCI_HandleAlloc((dvoid *) dp->ctx,
00555                                               (dvoid **) (void *) &dp->arr,
00556                                               (ub4) OCI_HTYPE_DIRPATH_COLUMN_ARRAY,
00557                                               (size_t) 0, (dvoid **) NULL));
00558     }
00559 
00560     /* allocate stream handle */
00561 
00562     if (res == TRUE)
00563     {
00564         res = (OCI_SUCCESS == OCI_HandleAlloc((dvoid *) dp->ctx,
00565                                               (dvoid **) (void *) &dp->strm,
00566                                               (ub4) OCI_HTYPE_DIRPATH_STREAM,
00567                                               (size_t) 0, (dvoid **) NULL));
00568     }
00569 
00570     /* check the number of rows allocated */
00571 
00572     if (res == TRUE)
00573     {
00574         ub4 num_rows = 0;
00575         ub4 size     = sizeof(num_rows);
00576 
00577         OCI_CALL2
00578         (
00579             res, dp->con,
00580 
00581             OCIAttrGet(dp->arr, OCI_HTYPE_DIRPATH_COLUMN_ARRAY, &num_rows,
00582                        &size, OCI_ATTR_NUM_ROWS, dp->con->err)
00583         )
00584 
00585         dp->nb_cur  = (ub2) num_rows;
00586         dp->nb_rows = (ub2) num_rows;
00587     }
00588 
00589     /* now, we need to allocate internal buffers */
00590 
00591     if (res == TRUE)
00592     {
00593 
00594         for (i = 0; i < dp->nb_cols; i++)
00595         {
00596             OCI_DirPathColumn *col = &dp->cols[i];
00597 
00598             /* data buffers */
00599 
00600             col->data = (ub1 *) OCI_MemAlloc(OCI_IPC_BUFF_ARRAY,
00601                                              (size_t) col->bufsize,
00602                                              (size_t) dp->nb_cur, TRUE);
00603 
00604             if (col->data == NULL)
00605             {
00606                 res = FALSE;
00607                 break;
00608             }
00609 
00610             /* data sizes */
00611 
00612             col->lens = (ub4 *) OCI_MemAlloc(OCI_IPC_BUFF_ARRAY, sizeof(ub4),
00613                                              (size_t) dp->nb_cur, TRUE);
00614 
00615             if (col->lens == NULL)
00616             {
00617                 res = FALSE;
00618                 break;
00619             }
00620 
00621             /* data flags */
00622 
00623             col->flags = (ub1 *) OCI_MemAlloc(OCI_IPC_BUFF_ARRAY, sizeof(ub1),
00624                                               (size_t) dp->nb_cur, TRUE);
00625 
00626             if (col->flags == NULL)
00627             {
00628                 res = FALSE;
00629                 break;
00630             }
00631         }
00632     }
00633 
00634     if (res == TRUE)
00635         dp->status = OCI_DPS_PREPARED;
00636 
00637     OCI_RESULT(res);
00638 
00639     return res;
00640 }
00641 
00642 /* --------------------------------------------------------------------------------------------- *
00643  * OCI_DirPathSetEntry
00644  * --------------------------------------------------------------------------------------------- */
00645 
00646 boolean OCI_API OCI_DirPathSetEntry
00647 (
00648     OCI_DirPath *dp,
00649     unsigned int row,
00650     unsigned int index,
00651     void        *value,
00652     unsigned int size,
00653     boolean      complete
00654 )
00655 {
00656     boolean res              = TRUE;
00657     OCI_DirPathColumn *dpcol = NULL;
00658     OCI_Column *col          = NULL;
00659 
00660     ub1 *data;
00661     ub1 flag;
00662 
00663     OCI_CHECK_PTR(OCI_IPC_DIRPATH, dp, FALSE);
00664 
00665     OCI_CHECK_DIRPATH_STATUS(dp, OCI_DPS_PREPARED, FALSE);
00666     OCI_CHECK_BOUND(dp->con, index, 1, dp->nb_cols, FALSE);
00667     OCI_CHECK_BOUND(dp->con, row, 1, dp->nb_cur, FALSE);
00668 
00669     dpcol = &dp->cols[index-1];
00670     col   = &dp->typinf->cols[dpcol->index];
00671 
00672     /* check size */
00673 
00674     if (size > dpcol->maxsize)
00675         size = (unsigned int) dpcol->maxsize;
00676 
00677     /* setup column flag */
00678 
00679     if (value == NULL)
00680     {
00681         flag = OCI_DIRPATH_COL_NULL;
00682     }
00683     else if (complete == TRUE)
00684     {
00685         flag = OCI_DIRPATH_COL_COMPLETE;
00686     }
00687     else
00688     {
00689         flag = OCI_DIRPATH_COL_PARTIAL;
00690     }
00691 
00692     /* for character based column, parameter size was the number of characters
00693      **/
00694 
00695     if (dpcol->sqlcode == SQLT_CHR)
00696     {
00697         size *= (unsigned int) sizeof(dtext);
00698     }
00699 
00700     /* get internal data cell */
00701 
00702     data = ((ub1 *) dpcol->data) + (size_t) ((row-1) * dpcol->bufsize);
00703 
00704     #if defined(OCI_CHECK_DATASTRINGS)
00705 
00706     /* we weed to pack the buffer if wchar_t is 4 bytes */
00707 
00708     if (dpcol->type == OCI_DDT_TEXT)
00709     {
00710         int osize = -1;
00711 
00712         OCI_GetOutputString(value, data, &size, sizeof(dtext), sizeof(odtext));
00713     }
00714     else
00715 
00716     #endif
00717 
00718     #if defined(OCI_USERDATA_WIDE)
00719 
00720     /* input Unicode numeric values causes oracle conversion error.
00721        so, let's convert them to ansi */
00722 
00723     if (dpcol->type == OCI_DDT_OTHERS)
00724     {
00725         size = (unsigned int) wcstombs((char *) data, value, dpcol->bufsize - 1);
00726     }
00727     else
00728 
00729     #endif
00730 
00731     /* if a format was provided for a numeric column, we convert the input
00732        buffer to a OCINumber */
00733 
00734     if (dpcol->type == OCI_DDT_NUMBER)
00735     {
00736         OCINumber *num = (OCINumber *) data;
00737 
00738         res = OCI_NumberConvertStr(dp->con, num, (dtext *) value, size,
00739                                    dpcol->format, dpcol->format_size);
00740 
00741         if (res == TRUE)
00742         {
00743             size = (unsigned int) num->OCINumberPart[0];
00744         }
00745     }
00746     else
00747     {
00748 
00749         #if defined(OCI_CHARSET_MIXED)
00750 
00751         /* with mixed charset builds, OCIDirPrepare() causes a segfault if the
00752            attribute OCI_ATTR_CHARSET_ID has been set with OCI_UTF16.
00753            In the OCILIB direct path implementation, the code is the same for
00754            Unicode and mixed charset. This only difference is the
00755            environment mode set of UTF16...
00756            So let's convert the data back to ANSI until Oracle corrects this bug */
00757 
00758         if (dpcol->type == OCI_DDT_TEXT)
00759         {
00760             size = (unsigned int) wcstombs((char *) data, value, dpcol->bufsize - 1);
00761         }
00762         else
00763         #endif
00764         {
00765             memcpy(data, value, (size_t) size);
00766         }
00767 
00768     }
00769 
00770     dpcol->lens[row-1]  = size;
00771     dpcol->flags[row-1] = flag;
00772 
00773     OCI_RESULT(res);
00774 
00775     return res;
00776 }
00777 
00778 /* --------------------------------------------------------------------------------------------- *
00779  * OCI_DirPathReset
00780  * --------------------------------------------------------------------------------------------- */
00781 
00782 boolean OCI_API OCI_DirPathReset
00783 (
00784     OCI_DirPath *dp
00785 )
00786 {
00787     boolean res = TRUE;
00788 
00789     OCI_CHECK_PTR(OCI_IPC_DIRPATH, dp, FALSE);
00790 
00791     /* reset array */
00792 
00793     OCI_CALL2
00794     (
00795         res, dp->con,
00796 
00797         OCIDirPathColArrayReset(dp->arr, dp->con->err)
00798     )
00799 
00800     /* reset stream */
00801 
00802     OCI_CALL2
00803     (
00804         res, dp->con,
00805 
00806         OCIDirPathStreamReset(dp->strm, dp->con->err)
00807     )
00808 
00809     OCI_RESULT(res);
00810 
00811     return res;
00812 }
00813 
00814 /* --------------------------------------------------------------------------------------------- *
00815  * OCI_DirPathConvert
00816  * --------------------------------------------------------------------------------------------- */
00817 
00818 unsigned int OCI_API OCI_DirPathConvert
00819 (
00820     OCI_DirPath *dp
00821 )
00822 {
00823     unsigned int res         = OCI_DPR_COMPLETE;
00824     OCI_DirPathColumn *dpcol = NULL;
00825     sword ret                = OCI_SUCCESS;
00826     ub1 *data;
00827     ub4 size;
00828     ub1 flag;
00829     ub2 i, j;
00830 
00831     OCI_CHECK_PTR(OCI_IPC_DIRPATH, dp, OCI_DPR_ERROR);
00832 
00833     OCI_CHECK_DIRPATH_STATUS(dp, OCI_DPS_PREPARED, OCI_DPR_ERROR);
00834 
00835     dp->err_col  = 0;
00836     dp->nb_prcsd = 0;
00837 
00838     /* set entries */
00839 
00840     for (i = 0; (i < dp->nb_cols) && (res == TRUE); i++)
00841     {
00842         dpcol = &(dp->cols[i]);
00843 
00844         for (j = (ub2) 0; (j < dp->nb_cur) && (res == TRUE); j++)
00845         {
00846             /* get internal data cell */
00847 
00848             data = ((ub1 *) dpcol->data) +  (size_t) (j * dpcol->bufsize);
00849             size = dpcol->lens[j];
00850             flag = dpcol->flags[j];
00851 
00852             if (dpcol->sqlcode == SQLT_NUM)
00853             {
00854                 OCINumber *num = (OCINumber *) data;
00855 
00856                 data = &num->OCINumberPart[1];
00857             }
00858 
00859             /* set entry value */
00860 
00861             OCI_CALL2
00862             (
00863                 res, dp->con,
00864 
00865                 OCIDirPathColArrayEntrySet(dp->arr, dp->con->err, (ub4) j,
00866                                            (ub2) (i), (ub1*) data,
00867                                            (ub4) size, flag)
00868             )
00869         }
00870     }
00871 
00872     if (res == TRUE)
00873     {
00874         /* conversion */
00875 
00876         ret = OCIDirPathColArrayToStream(dp->arr, dp->ctx,  dp->strm, dp->con->err,
00877                                          (ub4) dp->nb_cur, (ub4) 0);
00878 
00879         switch (ret)
00880         {
00881         case OCI_SUCCESS:
00882         {
00883             dp->status  = OCI_DPS_CONVERTED;
00884             dp->err_col = 0;
00885             dp->err_row = 0;
00886             res         = OCI_DPR_COMPLETE;
00887 
00888             break;
00889         }
00890         case OCI_ERROR:
00891         {
00892             res = OCI_DPR_ERROR;
00893 
00894             OCI_ExceptionOCI(dp->con->err, dp->con, NULL, FALSE);
00895 
00896             break;
00897         }
00898         case OCI_CONTINUE:
00899         {
00900             dp->status = OCI_DPS_CONVERTED;
00901             res        = OCI_DPR_FULL;
00902 
00903             break;
00904         }
00905         case OCI_NEED_DATA:
00906         {
00907             res = OCI_DPR_PARTIAL;
00908 
00909             break;
00910         }
00911 
00912         }
00913 
00914         if (ret != OCI_SUCCESS)
00915         {
00916             size = sizeof(dp->err_col);
00917 
00918             OCIAttrGet(dp->arr, OCI_HTYPE_DIRPATH_COLUMN_ARRAY, &dp->err_col,
00919                        &size, OCI_ATTR_COL_COUNT, dp->con->err);
00920 
00921             size = sizeof(dp->err_row);
00922 
00923             OCIAttrGet(dp->arr, OCI_HTYPE_DIRPATH_COLUMN_ARRAY, &dp->err_row,
00924                        &size, OCI_ATTR_ROW_COUNT, dp->con->err);
00925 
00926             dp->nb_prcsd = dp->err_row;
00927         }
00928         else
00929         {
00930             dp->nb_prcsd = dp->nb_cur;
00931         }
00932 
00933     }
00934     else
00935     {
00936         ret = OCI_ERROR;
00937     }
00938 
00939     OCI_RESULT(ret == OCI_SUCCESS);
00940 
00941     return res;
00942 }
00943 
00944 /* --------------------------------------------------------------------------------------------- *
00945  * OCI_DirPathLoad
00946  * --------------------------------------------------------------------------------------------- */
00947 
00948 unsigned int OCI_API OCI_DirPathLoad
00949 (
00950     OCI_DirPath *dp
00951 )
00952 {
00953     unsigned int res = OCI_DPR_COMPLETE;
00954     sword ret        = OCI_SUCCESS;
00955 
00956     OCI_CHECK_PTR(OCI_IPC_DIRPATH, dp, OCI_DPR_ERROR);
00957 
00958     OCI_CHECK_DIRPATH_STATUS(dp, OCI_DPS_CONVERTED, OCI_DPR_ERROR);
00959 
00960     dp->err_col  = 0;
00961     dp->nb_prcsd = 0;
00962 
00963     ret = OCIDirPathLoadStream(dp->ctx, dp->strm, dp->con->err);
00964 
00965     switch (ret)
00966     {
00967     case OCI_SUCCESS:
00968     {
00969         dp->status     = OCI_DPS_PREPARED;
00970         dp->nb_prcsd   = dp->nb_cur;
00971         dp->nb_loaded += dp->nb_prcsd;
00972         res            = OCI_DPR_COMPLETE;
00973 
00974         break;
00975     }
00976     case OCI_ERROR:
00977     {
00978         res = OCI_DPR_ERROR;
00979 
00980         OCI_ExceptionOCI(dp->con->err, dp->con, NULL, FALSE);
00981 
00982         break;
00983     }
00984     case OCI_NO_DATA:
00985     {
00986         res = OCI_DPR_EMPTY;
00987 
00988         break;
00989     }
00990     case OCI_NEED_DATA:
00991     {
00992         res = OCI_DPR_PARTIAL;
00993 
00994         break;
00995     }
00996 
00997     }
00998 
00999     if (ret != OCI_SUCCESS)
01000     {
01001         ub4 size = sizeof(dp->nb_prcsd);
01002 
01003         OCIAttrGet(dp->arr, OCI_HTYPE_DIRPATH_COLUMN_ARRAY, &dp->nb_prcsd,
01004                    &size, OCI_ATTR_NUM_ROWS, dp->con->err);
01005     }
01006 
01007     OCI_RESULT(ret == OCI_SUCCESS);
01008 
01009     return res;
01010 }
01011 
01012 /* --------------------------------------------------------------------------------------------- *
01013  * OCI_DirPathFinish
01014  * --------------------------------------------------------------------------------------------- */
01015 
01016 boolean OCI_API OCI_DirPathFinish
01017 (
01018     OCI_DirPath *dp
01019 )
01020 {
01021     boolean res = TRUE;
01022 
01023     OCI_CHECK_PTR(OCI_IPC_DIRPATH, dp, FALSE);
01024 
01025     OCI_CHECK_DIRPATH_STATUS(dp, OCI_DPS_PREPARED, FALSE);
01026 
01027     OCI_CALL2
01028     (
01029         res, dp->con,
01030 
01031         OCIDirPathFinish(dp->ctx, dp->con->err)
01032     )
01033 
01034     if (res == TRUE)
01035         dp->status = OCI_DPS_TERMINATED;
01036 
01037     OCI_RESULT(res);
01038 
01039     return res;
01040 }
01041 
01042 /* --------------------------------------------------------------------------------------------- *
01043  * OCI_DirPathAbort
01044  * --------------------------------------------------------------------------------------------- */
01045 
01046 boolean OCI_API OCI_DirPathAbort
01047 (
01048     OCI_DirPath *dp
01049 )
01050 {
01051     boolean res = TRUE;
01052 
01053     OCI_CHECK_PTR(OCI_IPC_DIRPATH, dp, FALSE);
01054 
01055     OCI_CHECK_DIRPATH_STATUS(dp, OCI_DPS_PREPARED, FALSE);
01056 
01057     OCI_CALL2
01058     (
01059         res, dp->con,
01060 
01061         OCIDirPathAbort(dp->ctx, dp->con->err)
01062     )
01063 
01064     if (res == TRUE)
01065         dp->status = OCI_DPS_TERMINATED;
01066 
01067     OCI_RESULT(res);
01068 
01069     return res;
01070 }
01071 
01072 /* --------------------------------------------------------------------------------------------- *
01073  * OCI_DirPathSave
01074  * --------------------------------------------------------------------------------------------- */
01075 
01076 boolean OCI_API OCI_DirPathSave
01077 (
01078     OCI_DirPath *dp
01079 )
01080 {
01081     boolean res = TRUE;
01082 
01083     OCI_CHECK_PTR(OCI_IPC_DIRPATH, dp, FALSE);
01084 
01085     OCI_CHECK_DIRPATH_STATUS(dp, OCI_DPS_PREPARED, FALSE);
01086 
01087     OCI_CALL2
01088     (
01089         res, dp->con,
01090 
01091         OCIDirPathDataSave(dp->ctx, dp->con->err, OCI_DIRPATH_DATASAVE_SAVEONLY)
01092     )
01093 
01094     OCI_RESULT(res);
01095 
01096     return res;
01097 }
01098 
01099 /* --------------------------------------------------------------------------------------------- *
01100  * OCI_DirPathFlushRow
01101  * --------------------------------------------------------------------------------------------- */
01102 
01103 boolean OCI_API OCI_DirPathFlushRow
01104 (
01105     OCI_DirPath *dp
01106 )
01107 {
01108     boolean res = TRUE;
01109 
01110     OCI_CHECK_PTR(OCI_IPC_DIRPATH, dp, FALSE);
01111 
01112     OCI_CHECK_DIRPATH_STATUS(dp, OCI_DPS_PREPARED, FALSE);
01113 
01114     OCI_CALL2
01115     (
01116         res, dp->con,
01117 
01118         OCIDirPathFlushRow(dp->ctx, dp->con->err)
01119     )
01120 
01121     OCI_RESULT(res);
01122 
01123     return res;
01124 }
01125 
01126 /* --------------------------------------------------------------------------------------------- *
01127  * OCI_DirPathSetCurrentRows
01128  * --------------------------------------------------------------------------------------------- */
01129 
01130 boolean OCI_API OCI_DirPathSetCurrentRows
01131 (
01132     OCI_DirPath *dp,
01133     unsigned int nb_rows
01134 )
01135 {
01136     boolean res = TRUE;
01137 
01138     OCI_CHECK_PTR(OCI_IPC_DIRPATH, dp, FALSE);
01139 
01140     OCI_CHECK_DIRPATH_STATUS(dp, OCI_DPS_PREPARED, FALSE);
01141 
01142     OCI_CHECK_BOUND(dp->con, nb_rows, 1, dp->nb_rows, FALSE);
01143 
01144     dp->nb_cur = (ub2) nb_rows;
01145 
01146     OCI_RESULT(res);
01147 
01148     return res;
01149 }
01150 
01151 /* --------------------------------------------------------------------------------------------- *
01152  * OCI_DirPathGetCurrentRows
01153  * --------------------------------------------------------------------------------------------- */
01154 
01155 unsigned int OCI_API OCI_DirPathGetCurrentRows
01156 (
01157     OCI_DirPath *dp
01158 )
01159 {
01160     OCI_CHECK_PTR(OCI_IPC_DIRPATH, dp, 0);
01161 
01162     OCI_RESULT(TRUE);
01163 
01164     return dp->nb_cur;
01165 }
01166 
01167 /* --------------------------------------------------------------------------------------------- *
01168  * OCI_DirPathGetMaxRows
01169  * --------------------------------------------------------------------------------------------- */
01170 
01171 unsigned int OCI_API OCI_DirPathGetMaxRows
01172 (
01173     OCI_DirPath *dp
01174 )
01175 {
01176     OCI_CHECK_PTR(OCI_IPC_DIRPATH, dp, 0);
01177 
01178     OCI_RESULT(TRUE);
01179 
01180     return dp->nb_rows;
01181 }
01182 
01183 /* --------------------------------------------------------------------------------------------- *
01184  * OCI_DirPathSetDateFormat
01185  * --------------------------------------------------------------------------------------------- */
01186 
01187 boolean OCI_API OCI_DirPathSetDateFormat
01188 (
01189     OCI_DirPath *dp,
01190     const mtext *format
01191 )
01192 {
01193     boolean res = TRUE;
01194     void *ostr  = NULL;
01195     int osize   = -1;
01196 
01197     OCI_CHECK_PTR(OCI_IPC_DIRPATH, dp, FALSE);
01198 
01199     OCI_CHECK_DIRPATH_STATUS(dp, OCI_DPS_NOT_PREPARED, FALSE);
01200 
01201     osize = -1;
01202     ostr  = OCI_GetInputMetaString(format, &osize);
01203 
01204     OCI_CALL2
01205     (
01206         res, dp->con,
01207 
01208         OCIAttrSet((dvoid *) dp->ctx, (ub4) OCI_HTYPE_DIRPATH_CTX,
01209                    (dvoid *) ostr, (ub4) osize,
01210                    (ub4) OCI_ATTR_DATEFORMAT, dp->con->err)
01211     )
01212 
01213     OCI_ReleaseMetaString(ostr);
01214 
01215     OCI_RESULT(res);
01216 
01217     return res;
01218 }
01219 
01220 /* --------------------------------------------------------------------------------------------- *
01221  * OCI_DirPathSetParallel
01222  * --------------------------------------------------------------------------------------------- */
01223 
01224 boolean OCI_API OCI_DirPathSetParallel
01225 (
01226     OCI_DirPath *dp,
01227     boolean      value
01228 )
01229 {
01230     boolean res = TRUE;
01231     ub1 enabled = (ub1) value;
01232 
01233     OCI_CHECK_PTR(OCI_IPC_DIRPATH, dp, FALSE);
01234 
01235     OCI_CHECK_DIRPATH_STATUS(dp, OCI_DPS_NOT_PREPARED, FALSE);
01236 
01237     OCI_CALL2
01238     (
01239         res, dp->con,
01240 
01241         OCIAttrSet((dvoid *) dp->ctx, (ub4) OCI_HTYPE_DIRPATH_CTX,
01242                    (dvoid *) &enabled, (ub4) sizeof(enabled),
01243                    (ub4) OCI_ATTR_DIRPATH_PARALLEL, dp->con->err)
01244     )
01245 
01246     OCI_RESULT(res);
01247 
01248     return res;
01249 }
01250 
01251 /* --------------------------------------------------------------------------------------------- *
01252  * OCI_DirPathSetNoLog
01253  * --------------------------------------------------------------------------------------------- */
01254 
01255 boolean OCI_API OCI_DirPathSetNoLog
01256 (
01257     OCI_DirPath *dp,
01258     boolean      value
01259 )
01260 {
01261     boolean res = TRUE;
01262     ub1 nolog   = (ub1) value;
01263 
01264     OCI_CHECK_PTR(OCI_IPC_DIRPATH, dp, FALSE);
01265 
01266     OCI_CHECK_DIRPATH_STATUS(dp, OCI_DPS_NOT_PREPARED, FALSE);
01267 
01268     OCI_CALL2
01269     (
01270         res, dp->con,
01271 
01272         OCIAttrSet((dvoid *) dp->ctx, (ub4) OCI_HTYPE_DIRPATH_CTX,
01273                    (dvoid *) &nolog, (ub4) sizeof(nolog),
01274                    (ub4) OCI_ATTR_DIRPATH_NOLOG, dp->con->err)
01275     )
01276 
01277     OCI_RESULT(res);
01278 
01279     return res;
01280 }
01281 
01282 /* --------------------------------------------------------------------------------------------- *
01283  * OCI_DirPathSetCacheSize
01284  * --------------------------------------------------------------------------------------------- */
01285 
01286 boolean OCI_API OCI_DirPathSetCacheSize
01287 (
01288     OCI_DirPath *dp,
01289     unsigned int size
01290 )
01291 {
01292     boolean res     = TRUE;
01293     ub4 cache_size  = size;
01294     boolean enabled = FALSE;
01295 
01296     OCI_CHECK_PTR(OCI_IPC_DIRPATH, dp, FALSE);
01297 
01298     OCI_CHECK_DIRPATH_DATE_CACHE_ENABLED(dp, FALSE);
01299 
01300     OCI_CHECK_DIRPATH_STATUS(dp, OCI_DPS_NOT_PREPARED, FALSE);
01301 
01302     #if OCI_VERSION_COMPILE >= OCI_9_2
01303 
01304     OCI_CALL2
01305     (
01306         res, dp->con,
01307 
01308         OCIAttrSet((dvoid *) dp->ctx, (ub4) OCI_HTYPE_DIRPATH_CTX,
01309                    (dvoid *) &cache_size, (ub4) sizeof(cache_size),
01310                    (ub4) OCI_ATTR_DIRPATH_DCACHE_SIZE, dp->con->err)
01311     )
01312 
01313     OCI_CALL2
01314     (
01315         res, dp->con,
01316 
01317         OCIAttrSet((dvoid *) dp->ctx, (ub4) OCI_HTYPE_DIRPATH_CTX,
01318                    (dvoid *) &enabled, (ub4) sizeof(enabled),
01319                    (ub4) OCI_ATTR_DIRPATH_DCACHE_DISABLE, dp->con->err)
01320     )
01321 
01322     #else
01323 
01324     OCI_NOT_USED(cache_size);
01325     OCI_NOT_USED(enabled);
01326 
01327     #endif
01328 
01329     OCI_RESULT(res);
01330 
01331     return res;
01332 }
01333 
01334 /* --------------------------------------------------------------------------------------------- *
01335  * OCI_DirPathSetBufferSize
01336  * --------------------------------------------------------------------------------------------- */
01337 
01338 boolean OCI_API OCI_DirPathSetBufferSize
01339 (
01340     OCI_DirPath *dp,
01341     unsigned int size
01342 )
01343 {
01344     boolean res = TRUE;
01345     ub4 bufsize = (ub4) size;
01346 
01347     OCI_CHECK_PTR(OCI_IPC_DIRPATH, dp, FALSE);
01348 
01349     OCI_CHECK_DIRPATH_STATUS(dp, OCI_DPS_NOT_PREPARED, FALSE);
01350 
01351     OCI_CALL2
01352     (
01353         res, dp->con,
01354 
01355         OCIAttrSet((dvoid *) dp->ctx, (ub4) OCI_HTYPE_DIRPATH_CTX,
01356                    (dvoid *) &bufsize, (ub4) sizeof(bufsize),
01357                    (ub4) OCI_ATTR_BUF_SIZE, dp->con->err)
01358     )
01359 
01360     OCI_RESULT(res);
01361 
01362     return res;
01363 }
01364 
01365 /* --------------------------------------------------------------------------------------------- *
01366  * OCI_DirPathGetRowCount
01367  * --------------------------------------------------------------------------------------------- */
01368 
01369 unsigned int OCI_API OCI_DirPathGetRowCount
01370 (
01371     OCI_DirPath *dp
01372 )
01373 {
01374     OCI_CHECK_PTR(OCI_IPC_DIRPATH, dp, FALSE);
01375 
01376     OCI_RESULT(TRUE);
01377 
01378     return dp->nb_loaded;
01379 }
01380 
01381 /* --------------------------------------------------------------------------------------------- *
01382  * OCI_DirPathGetAffectedRows
01383  * --------------------------------------------------------------------------------------------- */
01384 
01385 unsigned int OCI_API OCI_DirPathGetAffectedRows
01386 (
01387     OCI_DirPath *dp
01388 )
01389 {
01390     OCI_CHECK_PTR(OCI_IPC_DIRPATH, dp, FALSE);
01391 
01392     OCI_RESULT(TRUE);
01393 
01394     return dp->nb_prcsd;
01395 }
01396 
01397 /* --------------------------------------------------------------------------------------------- *
01398  * OCI_DirPathGetErrorColumn
01399  * --------------------------------------------------------------------------------------------- */
01400 
01401 unsigned int OCI_API OCI_DirPathGetErrorColumn
01402 (
01403     OCI_DirPath *dp
01404 )
01405 {
01406     OCI_CHECK_PTR(OCI_IPC_DIRPATH, dp, FALSE);
01407 
01408     OCI_RESULT(TRUE);
01409 
01410     return dp->err_col;
01411 }
01412 
01413 /* --------------------------------------------------------------------------------------------- *
01414  * OCI_DirPathGetErrorRow
01415  * --------------------------------------------------------------------------------------------- */
01416 
01417 unsigned int OCI_API OCI_DirPathGetErrorRow
01418 (
01419     OCI_DirPath *dp
01420 )
01421 {
01422     OCI_CHECK_PTR(OCI_IPC_DIRPATH, dp, FALSE);
01423 
01424     OCI_RESULT(TRUE);
01425 
01426     return dp->err_row;
01427 }

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