OCILIB (C Driver for Oracle) 3.9.2
D:/Perso/dev/ocilib/ocilib/src/ocilib_checks.h
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: ocilib_checks.h, v 3.9.2 2011-07-13 00:00 Vincent Rogier $
00033  * --------------------------------------------------------------------------------------------- */
00034 
00035 #ifndef OCILIB_OCILIB_CHECKS_H_INCLUDED
00036 #define OCILIB_OCILIB_CHECKS_H_INCLUDED
00037 
00038 /* ********************************************************************************************* *
00039                         MACROS FOR CHECKING OCI CALLS
00040  * ********************************************************************************************* */
00041 
00055 #define OCI_CALL0(res, err, fct)                                               \
00056                                                                                \
00057     {                                                                          \
00058         (res) = (boolean) fct;                                                 \
00059         if (OCI_NO_ERROR((res)) == FALSE)                                      \
00060         {                                                                      \
00061             (res) = ((res) == OCI_SUCCESS_WITH_INFO);                          \
00062             OCI_ExceptionOCI((err), NULL, NULL, res);                          \
00063         }                                                                      \
00064         else                                                                   \
00065             (res) = TRUE;                                                      \
00066     }
00067 
00084 #define OCI_CALL1(res, con, stmt, fct)                                         \
00085                                                                                \
00086     {                                                                          \
00087         if ((res) == TRUE)                                                     \
00088         {                                                                      \
00089             (res) = (boolean) fct;                                             \
00090             if (OCI_NO_ERROR((res)) == FALSE)                                  \
00091             {                                                                  \
00092                 (res) = ((res) == OCI_SUCCESS_WITH_INFO);                      \
00093                 OCI_ExceptionOCI((con)->err, (con), (stmt), res);              \
00094             }                                                                  \
00095             else                                                               \
00096                 (res) = TRUE;                                                  \
00097         }                                                                      \
00098     }
00099 
00115 #define OCI_CALL2(res, con, fct)                                               \
00116                                                                                \
00117     {                                                                          \
00118         if ((res) == TRUE)                                                     \
00119         {                                                                      \
00120             (res) = (boolean) fct;                                             \
00121             if (OCI_NO_ERROR((res)) == FALSE)                                  \
00122             {                                                                  \
00123                 (res) = ((res) == OCI_SUCCESS_WITH_INFO);                      \
00124                 OCI_ExceptionOCI((con)->err, (con), NULL, res);                \
00125             }                                                                  \
00126             else                                                               \
00127                 (res) = TRUE;                                                  \
00128         }                                                                      \
00129     }
00130 
00144 #define OCI_CALL3(res, err, fct)                                               \
00145                                                                                \
00146     {                                                                          \
00147         if ((res) == TRUE)                                                     \
00148         {                                                                      \
00149             (res) = (boolean) fct;                                             \
00150             if (OCI_NO_ERROR((res)) == FALSE)                                  \
00151             {                                                                  \
00152                 (res) = ((res) == OCI_SUCCESS_WITH_INFO);                      \
00153                 OCI_ExceptionOCI((err), NULL, NULL, res);                      \
00154             }                                                                  \
00155             else                                                               \
00156                 (res) = TRUE;                                                  \
00157         }                                                                      \
00158     }
00159 
00175 #define OCI_CALL4(res, err, con, fct)                                          \
00176                                                                                \
00177     {                                                                          \
00178         if ((res) == TRUE)                                                     \
00179         {                                                                      \
00180             (res) = (boolean) fct;                                             \
00181             if (OCI_NO_ERROR((res)) == FALSE)                                  \
00182             {                                                                  \
00183                 (res) = ((res) == OCI_SUCCESS_WITH_INFO);                      \
00184                 OCI_ExceptionOCI((err), (con), NULL, res);                     \
00185             }                                                                  \
00186             else                                                               \
00187                 (res) = TRUE;                                                  \
00188         }                                                                      \
00189     }
00190 
00207 #define OCI_CALL5(res, con, stmt, fct)                                         \
00208                                                                                \
00209     {                                                                          \
00210         (res) = (boolean) fct;                                                 \
00211         if (OCI_NO_ERROR((res)) == FALSE)                                      \
00212         {                                                                      \
00213             (res) = ((res) == OCI_SUCCESS_WITH_INFO);                          \
00214             OCI_WarningOCI((con)->err, (con), (stmt), res);                    \
00215         }                                                                      \
00216         else                                                                   \
00217             (res) = TRUE;                                                      \
00218     }
00219 
00220 /* ********************************************************************************************* *
00221                         PARAMETER CHECKING MACROS
00222  * ********************************************************************************************* */
00223 
00236 #define OCI_CHECK(exp, ret) if ((exp) == TRUE) return (ret);
00237 
00251 #define OCI_CHECK_PTR(type, ptr, ret)                                          \
00252                                                                                \
00253     if ((ptr) == NULL)                                                         \
00254     {                                                                          \
00255         OCI_ExceptionNullPointer(type);                                        \
00256                                                                                \
00257         return (ret);                                                          \
00258     }
00259 
00275 #define OCI_CHECK_BIND_CALL(stmt, name, data, type)                            \
00276                                                                                \
00277     OCI_CHECK_PTR(OCI_IPC_STATEMENT, stmt, FALSE);                             \
00278     OCI_CHECK_PTR(OCI_IPC_STRING, name, FALSE);                                \
00279     OCI_CHECK_STMT_STATUS(stmt, OCI_STMT_PREPARED, FALSE);                     \
00280     if (stmt->bind_alloc_mode == OCI_BAM_EXTERNAL)                             \
00281         OCI_CHECK_PTR(type, data, FALSE);
00282 
00283 
00295 #define OCI_CHECK_REGISTER_CALL(stmt, name)                                    \
00296                                                                                \
00297     OCI_CHECK_PTR(OCI_IPC_STATEMENT, stmt, FALSE);                             \
00298     OCI_CHECK_PTR(OCI_IPC_STRING, name, FALSE);                                \
00299 
00300 
00301 /* ********************************************************************************************* *
00302                         MISCELLANEOUS CHECKING MACROS
00303  * ********************************************************************************************* */
00304 
00320 #define OCI_CHECK_BOUND(con, v, b1, b2, ret)                                   \
00321                                                                                \
00322     if ((v < (b1)) || (v > (b2)))                                              \
00323     {                                                                          \
00324         OCI_ExceptionOutOfBounds((con), (v));                                  \
00325                                                                                \
00326         return (ret);                                                          \
00327     }
00328 
00344 #define OCI_CHECK_MIN(con, stmt, v, m, ret)                                    \
00345                                                                                \
00346     if ((v) < (m))                                                             \
00347     {                                                                          \
00348         OCI_ExceptionMinimumValue((con), (stmt), m);                           \
00349                                                                                \
00350         return (ret);                                                          \
00351     }
00352 
00366 #define OCI_CHECK_COMPAT(con, exp, ret)                                        \
00367                                                                                \
00368     if ((exp) == FALSE)                                                        \
00369     {                                                                          \
00370         OCI_ExceptionTypeNotCompatible((con));                                 \
00371                                                                                \
00372         return (ret);                                                          \
00373     }
00374 
00375 /* ********************************************************************************************* *
00376                   INTERNAL STATES/ATTRIBUTES CHECKING MACROS
00377  * ********************************************************************************************* */
00378 
00391 #define OCI_CHECK_OBJECT_FETCHED(obj, ret)                                     \
00392                                                                                \
00393     if ((obj)->hstate == OCI_OBJECT_FETCHED_CLEAN)                                                                                                                                   \
00394         return (ret);
00395 
00409 #define OCI_CHECK_STMT_STATUS(st, v, ret)                                      \
00410                                                                                \
00411     if ((((st)->status) & (v)) == 0)                                           \
00412     {                                                                          \
00413         OCI_ExceptionStatementState((st), v);                                  \
00414         return ret;                                                            \
00415     }                                                                          \
00416 
00417 
00430 #define OCI_CHECK_SCROLLABLE_CURSOR_ACTIVATED(st, ret)                         \
00431                                                                                \
00432     if (((st)->nb_rbinds > 0) ||                                               \
00433         ((st)->exec_mode != OCI_STMT_SCROLLABLE_READONLY))                     \
00434     {                                                                          \
00435         OCI_ExceptionStatementNotScrollable(st);                               \
00436         return ret;                                                            \
00437     }
00438 
00453 #define OCI_CHECK_DIRPATH_STATUS(dp, v, ret)                                   \
00454                                                                                \
00455     if ((dp)->status != (v))                                                   \
00456     {                                                                          \
00457         OCI_ExceptionDirPathState((dp), (dp)->status);                         \
00458         return ret;                                                            \
00459     }
00460 
00461 /* ********************************************************************************************* *
00462                     INTERNAL FEATURES AVAILABILITY CHECKING MACROS
00463  * ********************************************************************************************* */
00464 
00476 #define OCI_CHECK_INITIALIZED(ret)                                             \
00477                                                                                \
00478     if (OCILib.loaded == FALSE)                                                \
00479     {                                                                          \
00480         OCI_ExceptionNotInitialized();                                         \
00481         return ret;                                                            \
00482     }
00483 
00498 #define OCI_CHECK_FEATURE(con, feat, ver,  ret)                                    \
00499                                                                                    \
00500     if (OCILib.version_runtime < ver || (((con) != NULL) && (con)->ver_num < ver)) \
00501     {                                                                              \
00502         OCI_ExceptionNotAvailable(con, feat);                                      \
00503         return ret;                                                                \
00504     }
00505 
00518 #define OCI_CHECK_THREAD_ENABLED(ret)                                      \
00519                                                                            \
00520     if ((OCI_LIB_THREADED) == FALSE)                                       \
00521     {                                                                      \
00522         OCI_ExceptionNotMultithreaded();                                   \
00523         return ret;                                                        \
00524     }
00525 
00539 #define OCI_CHECK_TIMESTAMP_ENABLED(con,  ret)                                 \
00540                                                                                \
00541     OCI_CHECK_FEATURE(con, OCI_FEATURE_TIMESTAMP, OCI_9_0, ret)
00542 
00556 #define OCI_CHECK_INTERVAL_ENABLED OCI_CHECK_TIMESTAMP_ENABLED
00557 
00571 #define OCI_CHECK_SCROLLABLE_CURSOR_ENABLED(con, ret)                          \
00572                                                                                \
00573     OCI_CHECK_FEATURE(con, OCI_FEATURE_SCROLLABLE_CURSOR, OCI_9_0, ret)
00574 
00587 #define OCI_CHECK_STATEMENT_CACHING_ENABLED(ret)                               \
00588                                                                                \
00589     if (OCILib.version_runtime < OCI_9_2)                                      \
00590     {                                                                          \
00591         OCI_ExceptionNotAvailable((dp)->con, OCI_FEATURE_STATEMENT_CACHING);   \
00592         return ret;                                                            \
00593     }
00594 
00607 #define OCI_CHECK_DIRPATH_DATE_CACHE_ENABLED(dp,  ret)                         \
00608                                                                                \
00609     if (OCILib.version_runtime < OCI_9_2)                                      \
00610     {                                                                          \
00611         OCI_ExceptionNotAvailable((dp)->con, OCI_FEATURE_DIRPATH_DATE_CACHE);  \
00612         return ret;                                                            \
00613     }
00614 
00626 #define OCI_CHECK_REMOTE_DBS_CONTROL_ENABLED(ret)                              \
00627                                                                                \
00628     if (OCILib.version_runtime < OCI_10_2)                                     \
00629     {                                                                          \
00630         OCI_ExceptionNotAvailable(NULL, OCI_FEATURE_REMOTE_DBS_CONTROL);       \
00631         return ret;                                                            \
00632     }
00633 
00645 #define OCI_CHECK_DATABASE_NOTIFY_ENABLED(ret)                                 \
00646                                                                                \
00647     if (OCILib.version_runtime < OCI_10_2)                                     \
00648     {                                                                          \
00649         OCI_ExceptionNotAvailable(NULL, OCI_FEATURE_DATABASE_NOTIFY);          \
00650         return ret;                                                            \
00651     }
00652 
00665 #define OCI_CHECK_HIGH_AVAILABILITY_ENABLED(ret)                               \
00666                                                                                \
00667     if (OCILib.version_runtime < OCI_10_2)                                     \
00668     {                                                                          \
00669         OCI_ExceptionNotAvailable(NULL, OCI_FEATURE_HIGH_AVAILABILITY);        \
00670         return ret;                                                            \
00671     }
00672 #endif    /* OCILIB_OCILIB_CHECKS_H_INCLUDED */
00673 
00674