C:/Users/vincent/Data/Perso/dev/ocilib/ocilib/src/bind.c

00001 /*
00002    +----------------------------------------------------------------------+   
00003    |                                                                      |
00004    |                     OCILIB - C Driver for Oracle                     |
00005    |                                                                      |
00006    |                      (C Wrapper for Oracle OCI)                      |
00007    |                                                                      |
00008    +----------------------------------------------------------------------+
00009    |                      Website : http://www.ocilib.net                 |
00010    +----------------------------------------------------------------------+
00011    |               Copyright (c) 2007-2009 Vincent ROGIER                 |
00012    +----------------------------------------------------------------------+
00013    | This library is free software; you can redistribute it and/or        |
00014    | modify it under the terms of the GNU Lesser General Public           |
00015    | License as published by the Free Software Foundation; either         |
00016    | version 2 of the License, or (at your option) any later version.     |
00017    |                                                                      |
00018    | This library is distributed in the hope that it will be useful,      |
00019    | but WITHOUT ANY WARRANTY; without even the implied warranty of       |
00020    | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU    |
00021    | Lesser General Public License for more details.                      |
00022    |                                                                      |
00023    | You should have received a copy of the GNU Lesser General Public     |
00024    | License along with this library; if not, write to the Free           |
00025    | Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.   |
00026    +----------------------------------------------------------------------+
00027    |          Author: Vincent ROGIER <vince.rogier@gmail.com>             |
00028    +----------------------------------------------------------------------+ 
00029 */
00030 
00031 /* ------------------------------------------------------------------------ *
00032  * $Id: bind.c, v 3.4.0 2009-07-30 17:40 Vince $
00033  * ------------------------------------------------------------------------ */
00034 
00035 #include "ocilib_internal.h"
00036 
00037 /* ************************************************************************ *
00038  *                             PRIVATE FUNCTIONS
00039  * ************************************************************************ */
00040 
00041 /* ------------------------------------------------------------------------ *
00042  * OCI_BindFree
00043  * ------------------------------------------------------------------------ */
00044 
00045 boolean OCI_BindFree(OCI_Bind *bnd)
00046 {
00047     if (bnd->alloc == TRUE)
00048         OCI_FREE(bnd->buf.data);
00049 
00050     OCI_FREE(bnd->buf.inds);
00051     OCI_FREE(bnd->buf.lens);
00052     OCI_FREE(bnd->buf.temp);
00053 
00054     OCI_FREE(bnd->plrcds);
00055 
00056     OCI_FREE(bnd->name);
00057     OCI_FREE(bnd);
00058 
00059     return TRUE;
00060 }
00061 
00062 /* ************************************************************************ *
00063  *                            PUBLIC FUNCTIONS
00064  * ************************************************************************ */
00065 
00066 /* ------------------------------------------------------------------------ *
00067  * OCI_BindGetName
00068  * ------------------------------------------------------------------------ */
00069 
00070 const mtext * OCI_API OCI_BindGetName(OCI_Bind *bnd)
00071 {
00072     OCI_CHECK_PTR(OCI_IPC_BIND, bnd, NULL);
00073 
00074     OCI_RESULT(TRUE);
00075 
00076     return (const mtext *) bnd->name; 
00077 }
00078 
00079 /* ------------------------------------------------------------------------ *
00080  * OCI_BindGetType
00081  * ------------------------------------------------------------------------ */
00082 
00083 unsigned int OCI_API OCI_BindGetType(OCI_Bind *bnd)
00084 {
00085     OCI_CHECK_PTR(OCI_IPC_BIND, bnd, OCI_UNKNOWN);
00086 
00087     OCI_RESULT(TRUE);
00088 
00089     return (unsigned int) bnd->type; 
00090 }
00091 
00092 /* ------------------------------------------------------------------------ *
00093  * OCI_BindGetSubtype
00094  * ------------------------------------------------------------------------ */
00095 
00096 unsigned int OCI_API OCI_BindGetSubtype(OCI_Bind *bnd)
00097 {
00098     unsigned int type = OCI_UNKNOWN;
00099 
00100     OCI_CHECK_PTR(OCI_IPC_BIND, bnd, OCI_UNKNOWN);
00101 
00102     OCI_RESULT(TRUE);
00103 
00104     if (bnd->type == OCI_CDT_LONG      || 
00105         bnd->type == OCI_CDT_LOB       ||
00106         bnd->type == OCI_CDT_FILE      ||
00107         bnd->type == OCI_CDT_TIMESTAMP ||
00108         bnd->type == OCI_CDT_INTERVAL)
00109     {
00110         type = bnd->subtype;
00111     }
00112 
00113     return type;
00114 }
00115 
00116 /* ------------------------------------------------------------------------ *
00117  * OCI_BindGetDataCount
00118  * ------------------------------------------------------------------------ */
00119 
00120 unsigned int OCI_API OCI_BindGetDataCount(OCI_Bind *bnd)
00121 {
00122     OCI_CHECK_PTR(OCI_IPC_BIND, bnd, 0);
00123 
00124     OCI_RESULT(TRUE);
00125 
00126     return (unsigned int) bnd->buf.count; 
00127 }
00128 
00129 /* ------------------------------------------------------------------------ *
00130  * OCI_BindGetData
00131  * ------------------------------------------------------------------------ */
00132 
00133 void * OCI_API OCI_BindGetData(OCI_Bind *bnd)
00134 {
00135     OCI_CHECK_PTR(OCI_IPC_BIND, bnd, NULL);
00136 
00137     OCI_RESULT(TRUE);
00138 
00139     return (void *) bnd->input; 
00140 }
00141 
00142 /* ------------------------------------------------------------------------ *
00143  * OCI_BindGetStatement
00144  * ------------------------------------------------------------------------ */
00145 
00146 OCI_EXPORT OCI_Statement * OCI_API OCI_BindGetStatement(OCI_Bind *bnd)
00147 {
00148     OCI_CHECK_PTR(OCI_IPC_BIND, bnd, NULL);
00149 
00150     OCI_RESULT(TRUE);
00151 
00152     return bnd->stmt; 
00153 }
00154 
00155 /* ------------------------------------------------------------------------ *
00156  * OCI_BindSetDataSize
00157  * ------------------------------------------------------------------------ */
00158 
00159 boolean OCI_API OCI_BindSetDataSize(OCI_Bind *bnd, unsigned int size)
00160 {
00161     return OCI_BindSetDataSizeAtPos(bnd, 1, size);
00162 }
00163 
00164 /* ------------------------------------------------------------------------ *
00165  * OCI_BindSetDataSizeAtPos
00166  * ------------------------------------------------------------------------ */
00167 
00168 boolean OCI_API OCI_BindSetDataSizeAtPos(OCI_Bind *bnd, unsigned int position, 
00169                                          unsigned int size)
00170 {
00171     boolean res   = FALSE;
00172 
00173     OCI_CHECK_PTR(OCI_IPC_BIND, bnd, FALSE);
00174     OCI_CHECK_BOUND(bnd->stmt->con, position, 1, bnd->buf.count, FALSE);
00175     OCI_CHECK_MIN(bnd->stmt->con, bnd->stmt, size, 1, FALSE);
00176 
00177     if (bnd->buf.lens != NULL)
00178     {
00179         if (bnd->type == OCI_CDT_TEXT)
00180         {
00181             if (bnd->size == (sb4) size)
00182                 size += sizeof(odtext);
00183 
00184             size *= sizeof(odtext);
00185         }
00186 
00187         ((ub2 *) bnd->buf.lens)[position-1] = (ub2) size; 
00188 
00189         res = TRUE;
00190     }
00191 
00192     OCI_RESULT(TRUE);
00193 
00194     return res;
00195 }
00196 
00197 /* ------------------------------------------------------------------------ *
00198  * OCI_BindGetDataSize
00199  * ------------------------------------------------------------------------ */
00200 
00201 unsigned int OCI_API OCI_BindGetDataSize(OCI_Bind *bnd)
00202 {
00203     return OCI_BindGetDataSizeAtPos(bnd, 1);
00204 }
00205 
00206 /* ------------------------------------------------------------------------ *
00207  * OCI_BindGetDataSizeAtPos
00208  * ------------------------------------------------------------------------ */
00209 
00210 unsigned int OCI_API OCI_BindGetDataSizeAtPos(OCI_Bind *bnd, unsigned int position)
00211 {
00212     unsigned int size = 0;
00213 
00214     OCI_CHECK_PTR(OCI_IPC_BIND, bnd, 0);
00215     OCI_CHECK_BOUND(bnd->stmt->con, position, 1, bnd->buf.count, 0);
00216  
00217     if (bnd->buf.lens != NULL)
00218     {
00219         size = (unsigned int) ((ub2 *) bnd->buf.lens)[position-1];
00220 
00221         if (bnd->type == OCI_CDT_TEXT)
00222         {
00223             if (bnd->size == (sb4) size)
00224                 size -= sizeof(odtext);
00225 
00226             size /= sizeof(odtext);
00227         }
00228     }
00229 
00230     OCI_RESULT(TRUE);
00231 
00232     return size;
00233 }
00234 
00235 
00236 /* ------------------------------------------------------------------------ *
00237  * OCI_BindSetNullAtPos
00238  * ------------------------------------------------------------------------ */
00239 
00240 boolean OCI_API OCI_BindSetNullAtPos(OCI_Bind *bnd, unsigned int position)
00241 {
00242     OCI_CHECK_PTR(OCI_IPC_BIND, bnd, FALSE);
00243     OCI_CHECK_BOUND(bnd->stmt->con, position, 1, bnd->buf.count, FALSE);
00244 
00245     if (bnd->buf.inds != NULL)
00246         ((sb2*) bnd->buf.inds)[position-1] = -1;
00247 
00248     OCI_RESULT(TRUE);
00249 
00250     return TRUE;
00251 }
00252 
00253 /* ------------------------------------------------------------------------ *
00254  * OCI_BindSetNull
00255  * ------------------------------------------------------------------------ */
00256 
00257 boolean OCI_API OCI_BindSetNull(OCI_Bind *bnd)
00258 {
00259   return OCI_BindSetNullAtPos(bnd, 1);
00260 }
00261 
00262 /* ------------------------------------------------------------------------ *
00263  * OCI_BindIsNullAtPos
00264  * ------------------------------------------------------------------------ */
00265 
00266 boolean OCI_API OCI_BindIsNullAtPos(OCI_Bind *bnd, unsigned int position)
00267 {
00268     boolean ret = TRUE;
00269 
00270     OCI_CHECK_PTR(OCI_IPC_BIND, bnd, FALSE);
00271     OCI_CHECK_BOUND(bnd->stmt->con, position, 1, bnd->buf.count, FALSE);
00272 
00273     if (bnd->buf.inds != NULL)
00274         ret = (((sb2*) bnd->buf.inds)[position-1] == -1);
00275 
00276     OCI_RESULT(TRUE);
00277 
00278     return ret;
00279 }
00280 
00281 /* ------------------------------------------------------------------------ *
00282  * OCI_BindIsNull
00283  * ------------------------------------------------------------------------ */
00284 
00285 boolean OCI_API OCI_BindIsNull(OCI_Bind *bnd)
00286 {
00287   return OCI_BindIsNullAtPos(bnd, 1);
00288 }
00289 
00290 

Generated on Thu Jul 30 17:41:52 2009 for OCILIB (C Driver for Oracle) by  doxygen 1.5.4