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