OCILIB (C Driver for Oracle) 3.12.1
error.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-2013 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, 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                 {
00117                     OCI_ThreadKeySet(OCILib.key_errs, err);
00118                 }
00119             }
00120             else if (check == TRUE)
00121             {
00122                 if ((err->active == TRUE) || (err->warning != warning))
00123                 {
00124                     err = NULL;
00125                 }
00126             }
00127         }
00128     }
00129     else
00130     {
00131         err = &OCILib.lib_err;
00132 
00133         if (err != NULL)
00134         {
00135             if ((err->active == TRUE) || (err->warning != warning))
00136             {
00137                 err = NULL;
00138             }
00139         }
00140     }
00141 
00142     return err;
00143 }
00144 
00145 /* ********************************************************************************************* *
00146  *                             PUBLIC FUNCTIONS
00147  * ********************************************************************************************* */
00148 
00149 /* --------------------------------------------------------------------------------------------- *
00150  * OCI_ErrorGetString
00151  * --------------------------------------------------------------------------------------------- */
00152 
00153 const mtext * OCI_API OCI_ErrorGetString
00154 (
00155     OCI_Error *err
00156 )
00157 {
00158     OCI_CHECK(err == NULL, NULL);
00159 
00160     return err->str;
00161 }
00162 
00163 /* --------------------------------------------------------------------------------------------- *
00164  * OCI_ErrorGetType
00165  * --------------------------------------------------------------------------------------------- */
00166 
00167 unsigned int OCI_API OCI_ErrorGetType
00168 (
00169     OCI_Error *err
00170 )
00171 {
00172     OCI_CHECK(err == NULL, OCI_UNKNOWN);
00173 
00174     return err->type;
00175 }
00176 
00177 /* --------------------------------------------------------------------------------------------- *
00178  * OCI_ErrorGetOCICode
00179  * --------------------------------------------------------------------------------------------- */
00180 
00181 int OCI_API OCI_ErrorGetOCICode
00182 (
00183     OCI_Error *err
00184 )
00185 {
00186     OCI_CHECK(err == NULL, OCI_UNKNOWN);
00187 
00188     return (int) err->ocode;
00189 }
00190 
00191 /* --------------------------------------------------------------------------------------------- *
00192  * OCI_ErrorGetInternalCode
00193  * --------------------------------------------------------------------------------------------- */
00194 
00195 int OCI_API OCI_ErrorGetInternalCode
00196 (
00197     OCI_Error *err
00198 )
00199 {
00200     OCI_CHECK_PTR(OCI_IPC_ERROR, err, 0);
00201 
00202     return err->icode;
00203 }
00204 
00205 /* --------------------------------------------------------------------------------------------- *
00206  * OCI_ErrorGetConnection
00207  * --------------------------------------------------------------------------------------------- */
00208 
00209 OCI_Connection * OCI_API OCI_ErrorGetConnection
00210 (
00211     OCI_Error *err
00212 )
00213 {
00214     OCI_CHECK(err == NULL, NULL);
00215 
00216     return err->con;
00217 }
00218 
00219 /* --------------------------------------------------------------------------------------------- *
00220  * OCI_ErrorGetStatement
00221  * --------------------------------------------------------------------------------------------- */
00222 
00223 OCI_Statement * OCI_API OCI_ErrorGetStatement
00224 (
00225     OCI_Error *err
00226 )
00227 {
00228     OCI_CHECK(err == NULL, NULL);
00229 
00230     return err->stmt;
00231 }
00232 
00233 /* --------------------------------------------------------------------------------------------- *
00234  * OCI_ErrorGetRow
00235  * --------------------------------------------------------------------------------------------- */
00236 
00237 unsigned int OCI_API OCI_ErrorGetRow
00238 (
00239     OCI_Error *err
00240 )
00241 {
00242     OCI_CHECK(err == NULL, 0);
00243 
00244     return err->row;
00245 }