OCILIB (C Driver for Oracle) 3.12.1
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-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: ocilib_checks.h, 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_CALL1(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     OCI_CHECK_PTR(type, data, FALSE);
00281 
00297 #define OCI_CHECK_BIND_CALL2(stmt, name, data, type)                           \
00298                                                                                \
00299     OCI_CHECK_PTR(OCI_IPC_STATEMENT, stmt, FALSE);                             \
00300     OCI_CHECK_PTR(OCI_IPC_STRING, name, FALSE);                                \
00301     OCI_CHECK_STMT_STATUS(stmt, OCI_STMT_PREPARED, FALSE);                     \
00302     if (stmt->bind_alloc_mode == OCI_BAM_EXTERNAL)                             \
00303         OCI_CHECK_PTR(type, data, FALSE);
00304 
00316 #define OCI_CHECK_REGISTER_CALL(stmt, name)                                    \
00317                                                                                \
00318     OCI_CHECK_PTR(OCI_IPC_STATEMENT, stmt, FALSE);                             \
00319     OCI_CHECK_PTR(OCI_IPC_STRING, name, FALSE);                                \
00320 
00321 
00322 /* ********************************************************************************************* *
00323                         MISCELLANEOUS CHECKING MACROS
00324  * ********************************************************************************************* */
00325 
00341 #define OCI_CHECK_BOUND(con, v, b1, b2, ret)                                   \
00342                                                                                \
00343     if ((v < (b1)) || (v > (b2)))                                              \
00344     {                                                                          \
00345         OCI_ExceptionOutOfBounds((con), (v));                                  \
00346                                                                                \
00347         return (ret);                                                          \
00348     }
00349 
00365 #define OCI_CHECK_MIN(con, stmt, v, m, ret)                                    \
00366                                                                                \
00367     if ((v) < (m))                                                             \
00368     {                                                                          \
00369         OCI_ExceptionMinimumValue((con), (stmt), m);                           \
00370                                                                                \
00371         return (ret);                                                          \
00372     }
00373 
00387 #define OCI_CHECK_COMPAT(con, exp, ret)                                        \
00388                                                                                \
00389     if ((exp) == FALSE)                                                        \
00390     {                                                                          \
00391         OCI_ExceptionTypeNotCompatible((con));                                 \
00392                                                                                \
00393         return (ret);                                                          \
00394     }
00395 
00396 /* ********************************************************************************************* *
00397                   INTERNAL STATES/ATTRIBUTES CHECKING MACROS
00398  * ********************************************************************************************* */
00399 
00412 #define OCI_CHECK_OBJECT_FETCHED(obj, ret)                                     \
00413                                                                                \
00414     if ((obj)->hstate == OCI_OBJECT_FETCHED_CLEAN)                                                                                                                                   \
00415         return (ret);
00416 
00430 #define OCI_CHECK_STMT_STATUS(st, v, ret)                                      \
00431                                                                                \
00432     if ((((st)->status) & (v)) == 0)                                           \
00433     {                                                                          \
00434         OCI_ExceptionStatementState((st), v);                                  \
00435         return ret;                                                            \
00436     }                                                                          \
00437 
00438 
00451 #define OCI_CHECK_SCROLLABLE_CURSOR_ACTIVATED(st, ret)                         \
00452                                                                                \
00453     if (((st)->nb_rbinds > 0) ||                                               \
00454         ((st)->exec_mode != OCI_STMT_SCROLLABLE_READONLY))                     \
00455     {                                                                          \
00456         OCI_ExceptionStatementNotScrollable(st);                               \
00457         return ret;                                                            \
00458     }
00459 
00474 #define OCI_CHECK_DIRPATH_STATUS(dp, v, ret)                                   \
00475                                                                                \
00476     if ((dp)->status != (v))                                                   \
00477     {                                                                          \
00478         OCI_ExceptionDirPathState((dp), (dp)->status);                         \
00479         return ret;                                                            \
00480     }
00481 
00482 /* ********************************************************************************************* *
00483                     INTERNAL FEATURES AVAILABILITY CHECKING MACROS
00484  * ********************************************************************************************* */
00485 
00497 #define OCI_CHECK_INITIALIZED(ret)                                             \
00498                                                                                \
00499     if (OCILib.loaded == FALSE)                                                \
00500     {                                                                          \
00501         OCI_ExceptionNotInitialized();                                         \
00502         return ret;                                                            \
00503     }
00504 
00519 #define OCI_CHECK_FEATURE(con, feat, ver,  ret)                                    \
00520                                                                                    \
00521     if (OCILib.version_runtime < ver || (((con) != NULL) && (con)->ver_num < ver)) \
00522     {                                                                              \
00523         OCI_ExceptionNotAvailable(con, feat);                                      \
00524         return ret;                                                                \
00525     }
00526 
00539 #define OCI_CHECK_THREAD_ENABLED(ret)                                      \
00540                                                                            \
00541     if ((OCI_LIB_THREADED) == FALSE)                                       \
00542     {                                                                      \
00543         OCI_ExceptionNotMultithreaded();                                   \
00544         return ret;                                                        \
00545     }
00546 
00560 #define OCI_CHECK_TIMESTAMP_ENABLED(con,  ret)                                 \
00561                                                                                \
00562     OCI_CHECK_FEATURE(con, OCI_FEATURE_TIMESTAMP, OCI_9_0, ret)
00563 
00577 #define OCI_CHECK_INTERVAL_ENABLED OCI_CHECK_TIMESTAMP_ENABLED
00578 
00592 #define OCI_CHECK_SCROLLABLE_CURSOR_ENABLED(con, ret)                          \
00593                                                                                \
00594     OCI_CHECK_FEATURE(con, OCI_FEATURE_SCROLLABLE_CURSOR, OCI_9_0, ret)
00595 
00608 #define OCI_CHECK_STATEMENT_CACHING_ENABLED(ret)                               \
00609                                                                                \
00610     if (OCILib.version_runtime < OCI_9_2)                                      \
00611     {                                                                          \
00612         OCI_ExceptionNotAvailable((dp)->con, OCI_FEATURE_STATEMENT_CACHING);   \
00613         return ret;                                                            \
00614     }
00615 
00628 #define OCI_CHECK_DIRPATH_DATE_CACHE_ENABLED(dp,  ret)                         \
00629                                                                                \
00630     if (OCILib.version_runtime < OCI_9_2)                                      \
00631     {                                                                          \
00632         OCI_ExceptionNotAvailable((dp)->con, OCI_FEATURE_DIRPATH_DATE_CACHE);  \
00633         return ret;                                                            \
00634     }
00635 
00647 #define OCI_CHECK_REMOTE_DBS_CONTROL_ENABLED(ret)                              \
00648                                                                                \
00649     if (OCILib.version_runtime < OCI_10_2)                                     \
00650     {                                                                          \
00651         OCI_ExceptionNotAvailable(NULL, OCI_FEATURE_REMOTE_DBS_CONTROL);       \
00652         return ret;                                                            \
00653     }
00654 
00666 #define OCI_CHECK_DATABASE_NOTIFY_ENABLED(ret)                                 \
00667                                                                                \
00668     if (OCILib.version_runtime < OCI_10_2)                                     \
00669     {                                                                          \
00670         OCI_ExceptionNotAvailable(NULL, OCI_FEATURE_DATABASE_NOTIFY);          \
00671         return ret;                                                            \
00672     }
00673 
00686 #define OCI_CHECK_HIGH_AVAILABILITY_ENABLED(ret)                               \
00687                                                                                \
00688     if (OCILib.version_runtime < OCI_10_2)                                     \
00689     {                                                                          \
00690         OCI_ExceptionNotAvailable(NULL, OCI_FEATURE_HIGH_AVAILABILITY);        \
00691         return ret;                                                            \
00692     }
00693 
00705 #define OCI_CHECK_XA_ENABLED(mode, ret)                                         \
00706                                                                                \
00707     if ( (mode & OCI_SESSION_XA) && (OCILib.use_xa == FALSE ) )                \
00708     {                                                                          \
00709         OCI_ExceptionNotAvailable(NULL, OCI_FEATURE_XA);                       \
00710         return ret;                                                            \
00711     }
00712 
00713 
00714 #endif    /* OCILIB_OCILIB_CHECKS_H_INCLUDED */
00715 
00716