C:/Users/vincent/Data/Perso/dev/ocilib/ocilib/src/number.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: number.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_NumberGet
00043  * ------------------------------------------------------------------------ */
00044 
00045 boolean OCI_NumberGet(OCI_Connection *con,  OCINumber *data, void *value,
00046                       uword size, uword flag)
00047 {
00048     boolean res = TRUE;
00049 
00050     OCI_CHECK(con   == NULL, FALSE);
00051     OCI_CHECK(value == NULL, FALSE);
00052     OCI_CHECK(data  == NULL, FALSE);
00053         
00054     if (flag & OCI_NUM_DOUBLE)
00055     {
00056         OCI_CALL2
00057         (
00058             res, con, 
00059             
00060             OCINumberToReal(con->err, data, size, value)
00061         )
00062     }
00063     else
00064     {
00065         uword sign = OCI_NUMBER_SIGNED;
00066 
00067         if (flag & OCI_NUM_UNSIGNED)
00068             sign = OCI_NUMBER_UNSIGNED;
00069 
00070         OCI_CALL2
00071         (
00072             res, con, 
00073             
00074             OCINumberToInt(con->err, data, size, sign, value)
00075         )
00076     }
00077             
00078    return res;
00079 }
00080 
00081 /* ------------------------------------------------------------------------ *
00082  * OCI_NumberSet
00083  * ------------------------------------------------------------------------ */
00084 
00085 boolean OCI_NumberSet(OCI_Connection *con,  OCINumber *data, void *value, 
00086                       uword size, uword flag)
00087 {
00088     boolean res = TRUE;
00089 
00090     OCI_CHECK(con   == NULL, FALSE);
00091     OCI_CHECK(value == NULL, FALSE);
00092     OCI_CHECK(data  == NULL, FALSE);
00093         
00094     if (flag & OCI_NUM_DOUBLE)
00095     {
00096         OCI_CALL2
00097         (
00098             res, con, 
00099             
00100             OCINumberFromReal(con->err, value, size, (OCINumber *) data)
00101         )
00102     }
00103     else
00104     {
00105         uword sign = OCI_NUMBER_SIGNED;
00106 
00107         if (flag & OCI_NUM_UNSIGNED)
00108             sign = OCI_NUMBER_UNSIGNED;
00109 
00110         OCI_CALL2
00111         (
00112             res, con, 
00113             
00114             OCINumberFromInt(con->err, value, size, sign, (OCINumber *) data)
00115         )
00116     }
00117             
00118     return res;
00119 }
00120 
00121 
00122 /* ------------------------------------------------------------------------ *
00123  * OCI_NumberConvertStr
00124  * ------------------------------------------------------------------------ */
00125 
00126 boolean OCI_NumberConvertStr(OCI_Connection *con,  OCINumber *num, 
00127                             const dtext *str, int str_size, 
00128                             const mtext* fmt, ub4 fmt_size)
00129 {
00130     boolean res = TRUE;
00131     void *ostr1 = NULL;
00132     int  osize1 = str_size;
00133     void *ostr2 = NULL;
00134     int  osize2 = fmt_size;
00135 
00136 #ifdef OCI_CHARSET_MIXED
00137 
00138     mtext temp[OCI_SIZE_BUFFER + 1];
00139   
00140 #endif
00141 
00142     OCI_CHECK(con   == NULL, FALSE);
00143     OCI_CHECK(str   == NULL, FALSE);
00144     OCI_CHECK(fmt   == NULL, FALSE);
00145 
00146 #ifdef OCI_CHARSET_MIXED
00147 
00148     temp[0] = 0;
00149 
00150     ostr1  = temp;
00151     osize1 = (int) wcstombs(temp, str, OCI_SIZE_BUFFER + OCI_CVT_CHAR);
00152 
00153 #else
00154 
00155     ostr1 = OCI_GetInputDataString(str, &osize1);
00156 
00157 #endif
00158 
00159     ostr2 = OCI_GetInputMetaString(fmt, &osize2);
00160 
00161 
00162     memset(num, 0, sizeof(*num));
00163 
00164     OCI_CALL2
00165     (
00166         res, con, 
00167         
00168         OCINumberFromText(con->err, (oratext *) ostr1, (ub4) osize1,
00169                                     (oratext *) ostr2, (ub4) osize2, 
00170                                     (oratext *) NULL,  (ub4) 0, num)
00171     )
00172 
00173 #ifndef OCI_CHARSET_MIXED
00174 
00175     OCI_ReleaseDataString(ostr1);
00176 
00177 #endif
00178 
00179     OCI_ReleaseMetaString(ostr2);      
00180 
00181     return res;
00182  }
00183 
00184 
00185 /* ------------------------------------------------------------------------ *
00186  * OCI_NumberGetFromStr
00187  * ------------------------------------------------------------------------ */
00188 
00189 boolean OCI_NumberGetFromStr(OCI_Connection *con,  void *value, uword size,
00190                              uword type, const dtext *str, int str_size, 
00191                              const mtext* fmt, ub4 fmt_size)
00192 {
00193     OCINumber num;
00194   
00195     OCI_CHECK(value == NULL, FALSE);
00196   
00197     return (OCI_NumberConvertStr(con, &num, str, str_size, fmt, fmt_size) &&
00198             OCI_NumberGet(con, &num, value, size, type));
00199  }

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