OCILIB (C Driver for Oracle) 3.9.1
D:/Perso/dev/ocilib/ocilib/src/pool.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-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: Pool.c, v 3.9.1 2011-07-08 00:00 Vincent Rogier $
00033  * --------------------------------------------------------------------------------------------- */
00034 
00035 #include "ocilib_internal.h"
00036 
00037 /* ********************************************************************************************* *
00038  *                             PRIVATE FUNCTIONS
00039  * ********************************************************************************************* */
00040 
00041 /* --------------------------------------------------------------------------------------------- *
00042  * OCI_PoolClose
00043  * --------------------------------------------------------------------------------------------- */
00044 
00045 boolean OCI_PoolClose
00046 (
00047     OCI_Pool *pool
00048 )
00049 {
00050     boolean res = TRUE;
00051 
00052     OCI_CHECK_PTR(OCI_IPC_POOL, pool, FALSE);
00053 
00054     /* free all connections */
00055 
00056     OCI_ListForEach(pool->cons, (POCI_LIST_FOR_EACH) OCI_ConnectionClose);
00057     OCI_ListClear(pool->cons);
00058     OCI_ListFree(pool->cons);
00059 
00060     pool->cons = NULL;
00061 
00062     if (OCI_LIB_THREADED)
00063     {
00064         OCI_MutexFree(pool->mutex);
00065     }
00066 
00067  #if OCI_VERSION_COMPILE >= OCI_9_0
00068 
00069     if (OCILib.version_runtime >= OCI_9_0)
00070     {
00071         /* close pool handle */
00072 
00073         if (pool->handle != NULL)
00074         {
00075             if (pool->htype == OCI_HTYPE_CPOOL)
00076             {
00077                 OCI_CALL0
00078                 (
00079                     res, pool->err,
00080 
00081                     OCIConnectionPoolDestroy(pool->handle, pool->err,
00082                                              (ub4) OCI_DEFAULT)
00083                 )
00084             }
00085 
00086         #if OCI_VERSION_COMPILE >= OCI_9_2
00087 
00088             else
00089             {
00090                 OCI_CALL0
00091                 (
00092                     res, pool->err,
00093 
00094                     OCISessionPoolDestroy(pool->handle, pool->err,
00095                                           (ub4) OCI_SPD_FORCE)
00096                 )
00097             }
00098 
00099         #endif
00100 
00101             OCI_HandleFree((void *) pool->handle, (ub4) pool->htype);
00102         }
00103 
00104     #if OCI_VERSION_COMPILE >= OCI_9_2
00105 
00106         /* close authentification handle */
00107 
00108         if (pool->authp != NULL)
00109         {
00110             OCI_HandleFree((void *) pool->authp, (ub4) OCI_HTYPE_AUTHINFO);
00111         }
00112 
00113     #endif
00114 
00115         /* close error handle */
00116 
00117         if (pool->err != NULL)
00118         {
00119             OCI_HandleFree((void *) pool->err, (ub4) OCI_HTYPE_ERROR);
00120         }
00121     }
00122 
00123 #endif
00124 
00125     pool->err    = NULL;
00126     pool->handle = NULL;
00127     pool->authp  = NULL;
00128 
00129     /* free strings */
00130 
00131     OCI_FREE(pool->name);
00132     OCI_FREE(pool->db);
00133     OCI_FREE(pool->user);
00134     OCI_FREE(pool->pwd);
00135 
00136     return res;
00137 }
00138 
00139 /* ********************************************************************************************* *
00140  *                             PUBLIC FUNCTIONS
00141  * ********************************************************************************************* */
00142 
00143 /* --------------------------------------------------------------------------------------------- *
00144  * OCI_PoolCreate
00145  * --------------------------------------------------------------------------------------------- */
00146 
00147 OCI_Pool * OCI_API OCI_PoolCreate
00148 (
00149     const mtext *db,
00150     const mtext *user,
00151     const mtext *pwd,
00152     unsigned int type,
00153     unsigned int mode,
00154     unsigned int min_con,
00155     unsigned int max_con,
00156     unsigned int incr_con
00157 )
00158 {
00159     OCI_Pool *pool = NULL;
00160     OCI_Item *item = NULL;
00161     boolean res    = TRUE;
00162 
00163     OCI_CHECK_MIN(NULL, NULL, max_con, 1, NULL);
00164 
00165     /* let's be sure OCI_Initialize() has been called */
00166 
00167     OCI_CHECK_INITIALIZED(NULL);
00168 
00169     /* create pool object */
00170 
00171     item = OCI_ListAppend(OCILib.pools, sizeof(*pool));
00172 
00173     if (item != NULL)
00174     {
00175         pool = (OCI_Pool *) item->data;
00176 
00177         /* create internal lists */
00178 
00179         pool->cons = OCI_ListCreate(OCI_IPC_CONNECTION);
00180 
00181         if (OCI_LIB_THREADED)
00182         {
00183             /* create mutex for OCI_PoolGetConnection() */
00184 
00185             pool->mutex = OCI_MutexCreateInternal();
00186 
00187             res = (pool->mutex != NULL);
00188         }
00189     }
00190     else
00191     {
00192         res = FALSE;
00193     }
00194 
00195     /* set attributes */
00196 
00197     if (res == TRUE)
00198     {
00199 
00200         pool->mode = mode;
00201         pool->min  = min_con;
00202         pool->max  = max_con;
00203         pool->incr = incr_con;
00204 
00205         pool->db   = mtsdup(db   != NULL ? db   : MT(""));
00206         pool->user = mtsdup(user != NULL ? user : MT(""));
00207         pool->pwd  = mtsdup(pwd  != NULL ? pwd  : MT(""));
00208     }
00209 
00210 #if OCI_VERSION_COMPILE < OCI_9_2
00211 
00212     type = OCI_POOL_CONNECTION;
00213 
00214 #endif
00215 
00216 #if OCI_VERSION_COMPILE >= OCI_9_0
00217 
00218     if (res == TRUE)
00219     {
00220         if (type == OCI_POOL_CONNECTION)
00221         {
00222             pool->htype = OCI_HTYPE_CPOOL;
00223         }
00224 
00225     #if OCI_VERSION_COMPILE >= OCI_9_2
00226 
00227         else
00228         {
00229             pool->htype = OCI_HTYPE_SPOOL;
00230         }
00231 
00232     #endif
00233 
00234     }
00235 
00236     if (OCILib.version_runtime >= OCI_9_0)
00237     {
00238         int osize_name = -1;
00239         int osize_db   = -1;
00240         int osize_user = -1;
00241         int osize_pwd  = -1;
00242 
00243         void *ostr_name = NULL;
00244         void *ostr_db   = NULL;
00245         void *ostr_user = NULL;
00246         void *ostr_pwd  = NULL;
00247 
00248         /* allocate error handle */
00249 
00250         if (res == TRUE)
00251         {
00252             res = (OCI_SUCCESS == OCI_HandleAlloc((dvoid *) OCILib.env,
00253                                                   (dvoid **) (void *) &pool->err,
00254                                                   (ub4) OCI_HTYPE_ERROR,
00255                                                   (size_t) 0,
00256                                                   (dvoid **) NULL));
00257         }
00258 
00259         /* allocate pool handle */
00260 
00261         if (res == TRUE)
00262         {
00263             res = (OCI_SUCCESS == OCI_HandleAlloc((dvoid *) OCILib.env,
00264                                                   (dvoid **) (void *) &pool->handle,
00265                                                   (ub4) pool->htype,
00266                                                   (size_t) 0,
00267                                                   (dvoid **) NULL));
00268         }
00269 
00270     #if OCI_VERSION_COMPILE >= OCI_9_2
00271 
00272         /* allocate authentification handle */
00273 
00274         if (res == TRUE)
00275         {
00276             res = (OCI_SUCCESS == OCI_HandleAlloc((dvoid *) OCILib.env,
00277                                                   (dvoid **) (void *) &pool->authp,
00278                                                   (ub4) OCI_HTYPE_AUTHINFO,
00279                                                   (size_t) 0,
00280                                                   (dvoid **) NULL));
00281         }
00282 
00283     #endif
00284 
00285         /* create the pool */
00286 
00287         if (res == TRUE)
00288         {
00289             ostr_db   = OCI_GetInputMetaString(pool->db,   &osize_db);
00290             ostr_user = OCI_GetInputMetaString(pool->user, &osize_user);
00291             ostr_pwd  = OCI_GetInputMetaString(pool->pwd,  &osize_pwd);
00292 
00293             if (pool->htype == OCI_HTYPE_CPOOL)
00294             {
00295                 OCI_CALL3
00296                 (
00297                     res, pool->err,
00298 
00299                     OCIConnectionPoolCreate(OCILib.env, pool->err, pool->handle,
00300                                             (OraText **) (dvoid *) &ostr_name,
00301                                             (sb4*) &osize_name,
00302                                             (OraText *) ostr_db, (sb4) osize_db,
00303                                             (ub4) pool->min, (ub4) pool->max,
00304                                             (ub4) pool->incr, (OraText *) ostr_user,
00305                                             (sb4) osize_user, (OraText *) ostr_pwd,
00306                                             (sb4) osize_pwd,  (ub4) OCI_DEFAULT)
00307                 )
00308             }
00309 
00310         #if OCI_VERSION_COMPILE >= OCI_9_2
00311 
00312             else
00313             {
00314                 OCI_CALL3
00315                 (
00316                     res, pool->err,
00317 
00318                     OCISessionPoolCreate(OCILib.env, pool->err, pool->handle,
00319                                          (OraText **) (dvoid *) &ostr_name,
00320                                          (ub4*) &osize_name,
00321                                          (OraText *) ostr_db, (sb4) osize_db,
00322                                          (ub4) pool->min, (ub4) pool->max,
00323                                          (ub4) pool->incr, (OraText *) ostr_user,
00324                                          (sb4) osize_user, (OraText *) ostr_pwd,
00325                                          (sb4) osize_pwd,  (ub4) OCI_SPC_HOMOGENEOUS)
00326                 )
00327             }
00328 
00329         #endif
00330 
00331         #if OCI_VERSION_COMPILE >= OCI_9_2
00332 
00333             /* set session login attribute */
00334 
00335             OCI_CALL3
00336             (
00337                 res, pool->err,
00338 
00339                 OCIAttrSet((dvoid *) pool->authp, (ub4) OCI_HTYPE_AUTHINFO,
00340                            (dvoid *) ostr_user, (ub4) osize_user,
00341                            (ub4) OCI_ATTR_USERNAME, pool->err)
00342             )
00343 
00344             /* set session password attribute */
00345 
00346             OCI_CALL3
00347             (
00348                 res, pool->err,
00349 
00350                 OCIAttrSet((dvoid *) pool->authp, (ub4) OCI_HTYPE_AUTHINFO,
00351                            (dvoid *) ostr_pwd, (ub4) osize_pwd,
00352                            (ub4) OCI_ATTR_PASSWORD, pool->err)
00353             )
00354 
00355         #endif
00356 
00357         #if OCI_VERSION_COMPILE >= OCI_11_1
00358 
00359             /* set OCILIB's driver layer name attribute only for session pools here
00360                For standalone connections and connection pool this attribute is set
00361                in OCI_ConnectionLogon() */
00362 
00363             if ((pool->htype == OCI_HTYPE_SPOOL) && (OCILib.version_runtime >= OCI_11_1))
00364             {
00365                 int   osize = -1;
00366                 void *ostr  = OCI_GetInputMetaString(OCILIB_DRIVER_NAME, &osize);
00367 
00368                 OCI_CALL3
00369                 (
00370                     res, pool->err,
00371 
00372                     OCIAttrSet((dvoid *) pool->authp, (ub4) OCI_HTYPE_AUTHINFO,
00373                                (dvoid *) ostr, (ub4) osize,
00374                                (ub4) OCI_ATTR_DRIVER_NAME, pool->err)
00375                 )
00376 
00377                 OCI_ReleaseMetaString(ostr);
00378             }
00379 
00380         #endif
00381 
00382             OCI_ReleaseMetaString(ostr_db);
00383             OCI_ReleaseMetaString(ostr_user);
00384             OCI_ReleaseMetaString(ostr_pwd);
00385         }
00386 
00387         if ((res == TRUE) && (ostr_name != NULL))
00388         {
00389             pool->name = (mtext *) OCI_MemAlloc(OCI_IPC_STRING, sizeof(mtext),
00390                                                 (osize_name / (int) sizeof(omtext)) + 1,
00391                                                 FALSE);
00392 
00393             if (pool->name != NULL)
00394             {
00395                 OCI_CopyString(ostr_name, pool->name, &osize_name,
00396                                sizeof(omtext), sizeof(mtext));
00397             }
00398             else
00399             {
00400                 res = FALSE;
00401             }
00402         }
00403     }
00404 
00405 #endif
00406 
00407     /* on success, we allocate internal OCI connection objects for pool
00408        minimum size */
00409 
00410     if (res == TRUE)
00411     {
00412         OCI_Connection *cn;
00413         
00414         /* retrieve statement cache size */
00415 
00416         OCI_PoolGetStatementCacheSize(pool);
00417 
00418         /* for connection pools that do not handle the statement cache
00419            atribute, let's set the value with documented default cache size */
00420 
00421         if (pool->htype == OCI_HTYPE_CPOOL)
00422         {
00423             pool->cache_size = OCI_DEFAUT_STMT_CACHE_SIZE;
00424         }
00425 
00426         while ((min_con--) > 0)
00427         {
00428             cn = OCI_ConnectionAllocate(pool, pool->db, pool->user, pool->pwd, pool->mode);
00429         }
00430     }
00431     else
00432     {
00433         OCI_PoolFree(pool);
00434         pool = NULL;
00435     }
00436 
00437     OCI_RESULT(res);
00438 
00439     return pool;
00440 }
00441 
00442 /* --------------------------------------------------------------------------------------------- *
00443  * OCI_PoolFree
00444  * --------------------------------------------------------------------------------------------- */
00445 
00446 boolean OCI_API OCI_PoolFree
00447 (
00448     OCI_Pool *pool
00449 )
00450 {
00451     boolean res = TRUE;
00452 
00453     OCI_CHECK_PTR(OCI_IPC_POOL, pool, FALSE);
00454 
00455     res = OCI_PoolClose(pool);
00456 
00457     OCI_ListRemove(OCILib.pools, pool);
00458 
00459     OCI_FREE(pool);
00460 
00461     OCI_RESULT(res);
00462 
00463     return res;
00464 }
00465 
00466 /* --------------------------------------------------------------------------------------------- *
00467  * OCI_PoolGetConnection
00468  * --------------------------------------------------------------------------------------------- */
00469 
00470 OCI_Connection * OCI_API OCI_PoolGetConnection
00471 (
00472     OCI_Pool *pool,
00473     mtext    *tag
00474 )
00475 {
00476     OCI_Connection *con = NULL;
00477     OCI_Item *item      = NULL;
00478     boolean res         = FALSE;
00479     boolean found       = FALSE;
00480 
00481     OCI_CHECK_PTR(OCI_IPC_POOL, pool, NULL);
00482 
00483     if (OCI_LIB_THREADED)
00484     {
00485         OCI_MutexAcquire(pool->mutex);
00486     }
00487 
00488     /* first, try to find an unused OCI_Connection in list */
00489 
00490     item = pool->cons->head;
00491 
00492     while (item != NULL)
00493     {
00494         con = (OCI_Connection *) item->data;
00495 
00496         if (((OCILib.version_runtime >= OCI_9_0) && (con->cstate == OCI_CONN_ALLOCATED)) ||
00497             ((OCILib.version_runtime <  OCI_9_0) && (con->cstate == OCI_CONN_ATTACHED )))
00498         {
00499             found = TRUE;
00500             break;
00501         }
00502 
00503         item = item->next;
00504     }
00505 
00506     if (found == FALSE)
00507     {
00508         con = NULL;
00509 
00510         /* no available connection found ! Try to allocate a new one... */
00511 
00512         if (OCILib.version_runtime >= OCI_9_0 || pool->cons->count < pool->max)
00513         {
00514             ub4 i, nb;
00515             OCI_Connection *c = NULL;
00516 
00517             nb = pool->nb_opened + pool->incr;
00518 
00519             if (nb > pool->max)
00520             {
00521                 nb = pool->max;
00522             }
00523 
00524             for (i = pool->nb_opened; i < nb; i++)
00525             {
00526                 c = OCI_ConnectionAllocate(pool, pool->db, pool->user,
00527                                            pool->pwd, pool->mode);
00528 
00529                 if (i == pool->nb_opened && c != NULL)
00530                 {
00531                     con = c;
00532                 }
00533             }
00534         }
00535     }
00536 
00537     if (con != NULL)
00538     {
00539         res = TRUE;
00540 
00541         if (con->cstate == OCI_CONN_ALLOCATED)
00542         {
00543             res = res && OCI_ConnectionAttach(con);
00544         }
00545 
00546         res = res &&  OCI_ConnectionLogon(con, NULL, tag);
00547 
00548         if (res == FALSE)
00549         {
00550             OCI_ConnectionFree(con);
00551             con = NULL;
00552         }
00553     }
00554     else
00555     {
00556         con = NULL;
00557     }
00558 
00559     if (OCI_LIB_THREADED)
00560     {
00561         OCI_MutexRelease(pool->mutex);
00562     }
00563 
00564     /* for regular connection pool, set the statement cache size to 
00565        retreived connection */
00566 
00567  #if OCI_VERSION_COMPILE >= OCI_10_1
00568 
00569     if ((con != NULL) && (pool->htype == OCI_HTYPE_CPOOL))
00570     {
00571         unsigned int cache_size = OCI_PoolGetStatementCacheSize(pool);
00572 
00573         OCI_SetStatementCacheSize(con, cache_size);
00574     }
00575 
00576 #endif
00577 
00578     OCI_RESULT(res);
00579 
00580     return con;
00581 }
00582 
00583 /* --------------------------------------------------------------------------------------------- *
00584  * OCI_PoolGetTimeout
00585  * --------------------------------------------------------------------------------------------- */
00586 
00587 unsigned int OCI_API OCI_PoolGetTimeout
00588 (
00589     OCI_Pool *pool
00590 )
00591 {
00592     OCI_CHECK_PTR(OCI_IPC_POOL, pool, 0);
00593 
00594     OCI_RESULT(TRUE);
00595 
00596     return pool->timeout;
00597 }
00598 
00599 /* --------------------------------------------------------------------------------------------- *
00600  * OCI_PoolSetTimeout
00601  * --------------------------------------------------------------------------------------------- */
00602 
00603 boolean OCI_API OCI_PoolSetTimeout
00604 (
00605     OCI_Pool    *pool,
00606     unsigned int value
00607 )
00608 {
00609     boolean res = TRUE;
00610 
00611     OCI_CHECK_PTR(OCI_IPC_POOL, pool, FALSE);
00612 
00613 #if OCI_VERSION_COMPILE >= OCI_9_0
00614 
00615     if (OCILib.version_runtime >= OCI_9_0)
00616     {
00617         ub4 timeout = value;
00618         ub4 attr    = 0;
00619 
00620         if (pool->htype == OCI_HTYPE_CPOOL)
00621         {
00622             attr = OCI_ATTR_CONN_TIMEOUT;
00623         }
00624 
00625     #if OCI_VERSION_COMPILE >= OCI_9_2
00626 
00627         else
00628         {
00629             attr = OCI_ATTR_SPOOL_TIMEOUT;
00630         }
00631 
00632     #endif
00633 
00634         OCI_CALL3
00635         (
00636             res, pool->err,
00637 
00638             OCIAttrSet((dvoid *) pool->handle, (ub4) pool->htype,
00639                        (dvoid *) &timeout,(ub4) sizeof(timeout),
00640                        (ub4) attr, pool->err)
00641         )
00642     }
00643 
00644 #endif
00645 
00646     if (res == TRUE)
00647     {
00648         pool->timeout = value;
00649     }
00650 
00651     OCI_RESULT(res);
00652 
00653     return res;
00654 }
00655 
00656 /* --------------------------------------------------------------------------------------------- *
00657  * OCI_PoolGetNoWait
00658  * --------------------------------------------------------------------------------------------- */
00659 
00660 boolean OCI_API OCI_PoolGetNoWait
00661 (
00662     OCI_Pool *pool
00663 )
00664 {
00665     OCI_CHECK_PTR(OCI_IPC_POOL, pool, FALSE);
00666 
00667     OCI_RESULT(TRUE);
00668 
00669     return pool->nowait;
00670 }
00671 
00672 /* --------------------------------------------------------------------------------------------- *
00673  * OCI_PoolSetNoWait
00674  * --------------------------------------------------------------------------------------------- */
00675 
00676 boolean OCI_API OCI_PoolSetNoWait
00677 (
00678     OCI_Pool *pool,
00679     boolean   value
00680 )
00681 {
00682     boolean res = TRUE;
00683 
00684     OCI_CHECK_PTR(OCI_IPC_POOL, pool, 0);
00685 
00686  #if OCI_VERSION_COMPILE >= OCI_9_0
00687 
00688     if (OCILib.version_runtime >= OCI_9_0)
00689     {
00690         ub1 nowait = (ub1) value;
00691         ub4 attr   = 0;
00692 
00693         if (pool->htype == OCI_HTYPE_CPOOL)
00694         {
00695             attr = OCI_ATTR_CONN_NOWAIT;
00696         }
00697 
00698     #if OCI_VERSION_COMPILE >= OCI_9_2
00699 
00700         else
00701         {
00702             attr = OCI_ATTR_SPOOL_GETMODE;
00703 
00704             if (value == TRUE)
00705             {
00706                 nowait = (ub1) OCI_SPOOL_ATTRVAL_NOWAIT;
00707             }
00708             else
00709             {
00710                 nowait = (ub1) OCI_SPOOL_ATTRVAL_WAIT;
00711             }
00712         }
00713    #endif
00714 
00715         OCI_CALL3
00716         (
00717             res, pool->err,
00718 
00719             OCIAttrSet((dvoid *) pool->handle, (ub4) pool->htype,
00720                        (dvoid *) &nowait, (ub4) sizeof(nowait),
00721                        (ub4) attr, pool->err)
00722         )
00723     }
00724 
00725 #endif
00726 
00727     if (res == TRUE)
00728     {
00729         pool->nowait = value;
00730     }
00731 
00732     OCI_RESULT(res);
00733 
00734     return TRUE;
00735 }
00736 
00737 /* --------------------------------------------------------------------------------------------- *
00738  * OCI_PoolGetBusyCount
00739  * --------------------------------------------------------------------------------------------- */
00740 
00741 unsigned int OCI_API OCI_PoolGetBusyCount
00742 (
00743     OCI_Pool *pool
00744 )
00745 {
00746     boolean res = TRUE;
00747 
00748     OCI_CHECK_PTR(OCI_IPC_POOL, pool, 0);
00749 
00750 #if OCI_VERSION_COMPILE >= OCI_9_0
00751 
00752     if (OCILib.version_runtime >= OCI_9_0)
00753     {
00754         ub4 value = 0;
00755         ub4 attr  = 0;
00756 
00757         if (pool->htype == OCI_HTYPE_CPOOL)
00758         {
00759             attr = (ub4) OCI_ATTR_CONN_BUSY_COUNT;
00760         }
00761 
00762     #if OCI_VERSION_COMPILE >= OCI_9_2
00763 
00764         else
00765         {
00766             attr = (ub4) OCI_ATTR_SPOOL_BUSY_COUNT;
00767         }
00768 
00769     #endif
00770 
00771         OCI_CALL3
00772         (
00773             res, pool->err,
00774 
00775             OCIAttrGet((dvoid *) pool->handle,(ub4) pool->htype,
00776                        (dvoid *) &value, (ub4 *) NULL,
00777                        (ub4) attr, pool->err)
00778         )
00779 
00780         if (res == TRUE)
00781         {
00782             pool->nb_busy = value;
00783         }
00784     }
00785 
00786 #endif
00787 
00788     OCI_RESULT(res);
00789 
00790     return pool->nb_busy;
00791 }
00792 
00793 /* --------------------------------------------------------------------------------------------- *
00794  * OCI_PoolGetOpenedCount
00795  * --------------------------------------------------------------------------------------------- */
00796 
00797 unsigned int OCI_API OCI_PoolGetOpenedCount
00798 (
00799     OCI_Pool *pool
00800 )
00801 {
00802     boolean res = TRUE;
00803 
00804     OCI_CHECK_PTR(OCI_IPC_POOL, pool, 0);
00805 
00806 #if OCI_VERSION_COMPILE >= OCI_9_0
00807 
00808     if (OCILib.version_runtime >= OCI_9_0)
00809     {
00810         ub4 value = 0;
00811         ub4 attr  = 0;
00812 
00813         if (pool->htype == OCI_HTYPE_CPOOL)
00814         {
00815              attr = OCI_ATTR_CONN_OPEN_COUNT;
00816         }
00817 
00818     #if OCI_VERSION_COMPILE >= OCI_9_2
00819 
00820         else
00821         {
00822             attr = OCI_ATTR_SPOOL_OPEN_COUNT;
00823         }
00824 
00825     #endif
00826 
00827         OCI_CALL3
00828         (
00829             res, pool->err,
00830 
00831             OCIAttrGet((dvoid *) pool->handle, (ub4) pool->htype,
00832                        (dvoid *) &value, (ub4 *) NULL,
00833                        (ub4) attr, pool->err)
00834         )
00835 
00836         if (res == TRUE)
00837         {
00838             pool->nb_opened = value;
00839         }
00840     }
00841 
00842 #endif
00843 
00844     OCI_RESULT(res);
00845 
00846     return pool->nb_opened;
00847 }
00848 
00849 /* --------------------------------------------------------------------------------------------- *
00850  * OCI_PoolGetMin
00851  * --------------------------------------------------------------------------------------------- */
00852 
00853 unsigned int OCI_API OCI_PoolGetMin
00854 (
00855     OCI_Pool *pool
00856 )
00857 {
00858     OCI_CHECK_PTR(OCI_IPC_POOL, pool, 0);
00859 
00860     OCI_RESULT(TRUE);
00861 
00862     return pool->min;
00863 }
00864 
00865 /* --------------------------------------------------------------------------------------------- *
00866  * OCI_PoolGetMax
00867  * --------------------------------------------------------------------------------------------- */
00868 
00869 unsigned int OCI_API OCI_PoolGetMax
00870 (
00871     OCI_Pool *pool
00872 )
00873 {
00874     OCI_CHECK_PTR(OCI_IPC_POOL, pool, 0);
00875 
00876     OCI_RESULT(TRUE);
00877 
00878     return pool->max;
00879 }
00880 
00881 /* --------------------------------------------------------------------------------------------- *
00882  * OCI_PoolGetIncrement
00883  * --------------------------------------------------------------------------------------------- */
00884 
00885 unsigned int OCI_API OCI_PoolGetIncrement
00886 (
00887     OCI_Pool *pool
00888 )
00889 {
00890     OCI_CHECK_PTR(OCI_IPC_POOL, pool, 0);
00891 
00892     OCI_RESULT(TRUE);
00893 
00894     return pool->incr;
00895 }
00896 
00897 /* --------------------------------------------------------------------------------------------- *
00898  * OCI_PoolSetStatementCacheSize
00899  * --------------------------------------------------------------------------------------------- */
00900 
00901 boolean OCI_API OCI_PoolSetStatementCacheSize
00902 (
00903     OCI_Pool     *pool,
00904     unsigned int  value
00905 )
00906 {
00907     boolean res         = TRUE;
00908     ub4     cache_size  = value;
00909 
00910     OCI_CHECK_PTR(OCI_IPC_POOL, pool, FALSE);
00911 
00912  #if OCI_VERSION_COMPILE >= OCI_10_1
00913 
00914     if (OCILib.version_runtime >= OCI_10_1)
00915     {
00916         if (pool->htype == OCI_HTYPE_SPOOL)
00917         {
00918             OCI_CALL3
00919             (
00920                 res, pool->err,
00921 
00922                 OCIAttrSet((dvoid *) pool->handle, (ub4) pool->htype,
00923                            (dvoid *) &cache_size, (ub4) sizeof(cache_size),
00924                            (ub4) OCI_ATTR_SPOOL_STMTCACHESIZE, pool->err)
00925             )
00926         }
00927     }
00928 
00929 #endif
00930 
00931     if (res == TRUE)
00932     {
00933         pool->cache_size = cache_size;
00934     }
00935 
00936     OCI_RESULT(res);
00937 
00938     return TRUE;
00939 }
00940 
00941 /* --------------------------------------------------------------------------------------------- *
00942  * OCI_PoolGetStatementCacheSize
00943  * --------------------------------------------------------------------------------------------- */
00944 
00945 unsigned int OCI_API OCI_PoolGetStatementCacheSize
00946 (
00947     OCI_Pool *pool
00948 )
00949 {
00950     boolean res = TRUE;
00951     ub4     cache_size = 0;
00952 
00953     OCI_CHECK_PTR(OCI_IPC_POOL, pool, 0);
00954 
00955  #if OCI_VERSION_COMPILE >= OCI_10_1
00956 
00957     if (OCILib.version_runtime >= OCI_10_1)
00958     {
00959         if (pool->htype == OCI_HTYPE_SPOOL)
00960         {
00961             OCI_CALL3
00962             (
00963                 res, pool->err,
00964 
00965                 OCIAttrGet((dvoid **) pool->handle, (ub4) pool->htype,
00966                            (dvoid *) &cache_size, (ub4 *) NULL,  
00967                            (ub4) OCI_ATTR_STMTCACHESIZE, pool->err)
00968             )
00969 
00970             if (res == TRUE)
00971             {
00972                 pool->cache_size = cache_size;
00973             }
00974         }
00975     }
00976 
00977 #endif
00978 
00979     OCI_RESULT(TRUE);
00980 
00981     return pool->cache_size;
00982 }
00983