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