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