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

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

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