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: error.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_ErrorCreate 00043 * --------------------------------------------------------------------------------------------- */ 00044 00045 OCI_Error * OCI_ErrorCreate 00046 ( 00047 void 00048 ) 00049 { 00050 OCI_Error *err = calloc(1, sizeof(*err)); 00051 00052 return err; 00053 } 00054 00055 /* --------------------------------------------------------------------------------------------- * 00056 * OCI_ErrorFree 00057 * --------------------------------------------------------------------------------------------- */ 00058 00059 void OCI_ErrorFree 00060 ( 00061 OCI_Error *err 00062 ) 00063 { 00064 OCI_FREE(err); 00065 } 00066 00067 /* --------------------------------------------------------------------------------------------- * 00068 * OCI_ErrorReset 00069 * --------------------------------------------------------------------------------------------- */ 00070 00071 void OCI_ErrorReset 00072 ( 00073 OCI_Error *err 00074 ) 00075 { 00076 if (err != NULL) 00077 { 00078 err->warning = FALSE; 00079 err->raise = TRUE; 00080 err->active = FALSE; 00081 err->con = NULL; 00082 err->stmt = NULL; 00083 err->ocode = 0; 00084 err->icode = 0; 00085 err->type = 0; 00086 err->str[0] = 0; 00087 } 00088 } 00089 00090 /* --------------------------------------------------------------------------------------------- * 00091 * OCI_ErrorGet 00092 * --------------------------------------------------------------------------------------------- */ 00093 00094 OCI_Error * OCI_ErrorGet 00095 ( 00096 boolean check, 00097 boolean warning 00098 ) 00099 { 00100 OCI_Error *err = NULL; 00101 00102 if ((warning == TRUE) && (OCILib.warnings_on == FALSE)) 00103 { 00104 return NULL; 00105 } 00106 00107 if (OCILib.loaded == TRUE) 00108 { 00109 if (OCI_ThreadKeyGet(OCILib.key_errs, ( void **) (dvoid *) &err) == TRUE) 00110 { 00111 if (err == NULL) 00112 { 00113 err = OCI_ErrorCreate(); 00114 00115 if (err != NULL) 00116 OCI_ThreadKeySet(OCILib.key_errs, err); 00117 } 00118 else if (check == TRUE) 00119 { 00120 if ((err->active == TRUE) || (err->warning != warning)) 00121 err = NULL; 00122 } 00123 } 00124 } 00125 else 00126 { 00127 err = &OCILib.lib_err; 00128 00129 if (err != NULL) 00130 { 00131 if ((err->active == TRUE) || (err->warning != warning)) 00132 err = NULL; 00133 } 00134 } 00135 00136 return err; 00137 } 00138 00139 /* ********************************************************************************************* * 00140 * PUBLIC FUNCTIONS 00141 * ********************************************************************************************* */ 00142 00143 /* --------------------------------------------------------------------------------------------- * 00144 * OCI_ErrorGetString 00145 * --------------------------------------------------------------------------------------------- */ 00146 00147 const mtext * OCI_API OCI_ErrorGetString 00148 ( 00149 OCI_Error *err 00150 ) 00151 { 00152 OCI_CHECK(err == NULL, NULL); 00153 00154 return err->str; 00155 } 00156 00157 /* --------------------------------------------------------------------------------------------- * 00158 * OCI_ErrorGetType 00159 * --------------------------------------------------------------------------------------------- */ 00160 00161 unsigned int OCI_API OCI_ErrorGetType 00162 ( 00163 OCI_Error *err 00164 ) 00165 { 00166 OCI_CHECK(err == NULL, OCI_UNKNOWN); 00167 00168 return err->type; 00169 } 00170 00171 /* --------------------------------------------------------------------------------------------- * 00172 * OCI_ErrorGetOCICode 00173 * --------------------------------------------------------------------------------------------- */ 00174 00175 int OCI_API OCI_ErrorGetOCICode 00176 ( 00177 OCI_Error *err 00178 ) 00179 { 00180 OCI_CHECK(err == NULL, OCI_UNKNOWN); 00181 00182 return (int) err->ocode; 00183 } 00184 00185 /* --------------------------------------------------------------------------------------------- * 00186 * OCI_ErrorGetInternalCode 00187 * --------------------------------------------------------------------------------------------- */ 00188 00189 int OCI_API OCI_ErrorGetInternalCode 00190 ( 00191 OCI_Error *err 00192 ) 00193 { 00194 OCI_CHECK_PTR(OCI_IPC_ERROR, err, 0); 00195 00196 return err->icode; 00197 } 00198 00199 /* --------------------------------------------------------------------------------------------- * 00200 * OCI_ErrorGetConnection 00201 * --------------------------------------------------------------------------------------------- */ 00202 00203 OCI_Connection * OCI_API OCI_ErrorGetConnection 00204 ( 00205 OCI_Error *err 00206 ) 00207 { 00208 OCI_CHECK(err == NULL, NULL); 00209 00210 return err->con; 00211 } 00212 00213 /* --------------------------------------------------------------------------------------------- * 00214 * OCI_ErrorGetStatement 00215 * --------------------------------------------------------------------------------------------- */ 00216 00217 OCI_Statement * OCI_API OCI_ErrorGetStatement 00218 ( 00219 OCI_Error *err 00220 ) 00221 { 00222 OCI_CHECK(err == NULL, NULL); 00223 00224 return err->stmt; 00225 } 00226 00227 /* --------------------------------------------------------------------------------------------- * 00228 * OCI_ErrorGetRow 00229 * --------------------------------------------------------------------------------------------- */ 00230 00231 unsigned int OCI_API OCI_ErrorGetRow 00232 ( 00233 OCI_Error *err 00234 ) 00235 { 00236 OCI_CHECK(err == NULL, 0); 00237 00238 return err->row; 00239 }