• Main Page
  • Modules
  • Data Structures
  • Files
  • File List

D:/Perso/dev/ocilib/ocilib/src/connection.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-2010 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: connection.c, v 3.8.0 2010-10-24 21:53 Vincent Rogier $
00033  * --------------------------------------------------------------------------------------------- */
00034 
00035 #include "ocilib_internal.h"
00036 
00037 /* ********************************************************************************************* *
00038  *                             PRIVATE FUNCTIONS
00039  * ********************************************************************************************* */
00040 
00041 /* --------------------------------------------------------------------------------------------- *
00042  * OCI_ConnectionAllocate
00043  * --------------------------------------------------------------------------------------------- */
00044 
00045 OCI_Connection * OCI_ConnectionAllocate
00046 (
00047     OCI_Pool    *pool,
00048     const mtext *db,
00049     const mtext *user,
00050     const mtext *pwd,
00051     unsigned int mode
00052 )
00053 {
00054     OCI_Connection *con = NULL;
00055     OCI_List *list      = NULL;
00056     OCI_Item *item      = NULL;
00057     boolean res         = TRUE;
00058 
00059     /* create connection object */
00060 
00061     if (pool != NULL)
00062         list = pool->cons;
00063     else
00064         list = OCILib.cons;
00065 
00066     item = OCI_ListAppend(list, sizeof(*con));
00067 
00068     if (item != NULL)
00069     {
00070         con = (OCI_Connection *) item->data;
00071 
00072         /* create internal lists */
00073 
00074         con->stmts = OCI_ListCreate(OCI_IPC_STATEMENT);
00075 
00076         if (res == TRUE)
00077         {
00078             con->tinfs = OCI_ListCreate(OCI_IPC_TYPE_INFO);
00079             res        = (con->tinfs != NULL);
00080         }
00081 
00082         if (res == TRUE)
00083         {
00084             con->trsns = OCI_ListCreate(OCI_IPC_TRANSACTION);
00085             res        = (con->trsns != NULL);
00086         }
00087 
00088         /* set attributes */
00089 
00090         if (res == TRUE)
00091         {
00092             con->mode     = mode;
00093             con->pool     = pool;
00094             con->sess_tag = NULL;
00095 
00096             if (con->pool != NULL)
00097             {
00098                 con->db   = (mtext *) db;
00099                 con->user = (mtext *) user;
00100                 con->pwd  = (mtext *) pwd;
00101             }
00102             else
00103             {
00104                 con->db   = mtsdup(db   != NULL ? db   : MT(""));
00105                 con->user = mtsdup(user != NULL ? user : MT(""));
00106                 con->pwd  = mtsdup(pwd  != NULL ? pwd  : MT(""));
00107             }
00108         }
00109 
00110         /*  allocate error handle */
00111 
00112         if (res == TRUE)
00113             res = (OCI_SUCCESS == OCI_HandleAlloc((dvoid *) OCILib.env,
00114                                                   (dvoid **) (void *) &con->err,
00115                                                   (ub4) OCI_HTYPE_ERROR,
00116                                                   (size_t) 0, (dvoid **) NULL));
00117     }
00118     else
00119         res = FALSE;
00120 
00121     /* update internal status */
00122 
00123     if (res == TRUE)
00124     {
00125         con->cstate = OCI_CONN_ALLOCATED;
00126     }
00127     else
00128     {
00129         OCI_ConnectionFree(con);
00130         con = NULL;
00131     }
00132 
00133     return con;
00134 }
00135 
00136 /* --------------------------------------------------------------------------------------------- *
00137  * OCI_ConnectionDeallocate
00138  * --------------------------------------------------------------------------------------------- */
00139 
00140 boolean OCI_ConnectionDeallocate
00141 (
00142     OCI_Connection *con
00143 )
00144 {
00145     OCI_CHECK(con == NULL, FALSE);
00146     OCI_CHECK(con->cstate != OCI_CONN_ALLOCATED, FALSE);
00147 
00148     /* close error handle */
00149 
00150     if (con->err != NULL)
00151         OCI_HandleFree((dvoid *) con->err, (ub4) OCI_HTYPE_ERROR);
00152 
00153     con->cxt = NULL;
00154     con->ses = NULL;
00155     con->svr = NULL;
00156     con->err = NULL;
00157 
00158     return TRUE;
00159 }
00160 
00161 /* --------------------------------------------------------------------------------------------- *
00162  * OCI_ConnectionAttach
00163  * --------------------------------------------------------------------------------------------- */
00164 
00165 boolean OCI_ConnectionAttach
00166 (
00167     OCI_Connection *con
00168 )
00169 {
00170     void *ostr  = NULL;
00171     int osize   = -1;
00172     boolean res = TRUE;
00173     ub4 cmode   = OCI_DEFAULT;
00174 
00175     OCI_CHECK(con == NULL, FALSE);
00176     OCI_CHECK(con->cstate != OCI_CONN_ALLOCATED, FALSE);
00177 
00178     /* allocate server handle for non pooled conenction */
00179 
00180     if (con->pool == NULL)
00181     {
00182         res = (OCI_SUCCESS == OCI_HandleAlloc((dvoid *) OCILib.env,
00183                                               (dvoid **) (void *) &con->svr,
00184                                               (ub4) OCI_HTYPE_SERVER,
00185                                               (size_t) 0, (dvoid **) NULL));
00186 
00187         /* attach server handle to service name */
00188 
00189         #if OCI_VERSION_COMPILE >= OCI_9_0
00190 
00191         if (OCILib.version_runtime >= OCI_9_0 && con->pool != NULL)
00192         {
00193             ostr  = OCI_GetInputMetaString(con->pool->name, &osize);
00194             cmode = OCI_CPOOL;
00195         }
00196         else
00197 
00198         #endif
00199 
00200         {
00201             ostr = OCI_GetInputMetaString(con->db, &osize);
00202         }
00203 
00204         OCI_CALL2
00205         (
00206             res, con,
00207 
00208             OCIServerAttach(con->svr, con->err,(OraText *) ostr,
00209                             (sb4) osize, cmode)
00210         )
00211 
00212         OCI_ReleaseMetaString(ostr);
00213     }
00214 
00215     /* handle errors */
00216 
00217     if (res == TRUE)
00218     {
00219         if (OCILib.version_runtime < OCI_9_0 && con->pool != NULL)
00220             con->pool->nb_opened++;
00221 
00222         con->cstate = OCI_CONN_ATTACHED;
00223     }
00224 
00225     return res;
00226 }
00227 
00228 /* --------------------------------------------------------------------------------------------- *
00229  * OCI_ConnectionDetach
00230  * --------------------------------------------------------------------------------------------- */
00231 
00232 boolean OCI_ConnectionDetach
00233 (
00234     OCI_Connection *con
00235 )
00236 {
00237     boolean res = TRUE;
00238 
00239     OCI_CHECK(con == NULL, FALSE);
00240     OCI_CHECK(con->cstate != OCI_CONN_ATTACHED, FALSE);
00241 
00242     if (con->svr != NULL)
00243     {
00244         /* detach from the oracle server */
00245 
00246         OCI_CALL2
00247         (
00248             res, con,
00249 
00250             OCIServerDetach(con->svr, con->err, (ub4) OCI_DEFAULT)
00251         )
00252 
00253         /* close server handle */
00254 
00255         OCI_HandleFree((dvoid *) con->svr, (ub4) OCI_HTYPE_SERVER);
00256 
00257         con->svr = NULL;
00258     }
00259 
00260     /* update internal status */
00261 
00262     if (res == TRUE)
00263     {
00264         if (OCILib.version_runtime < OCI_9_0 && con->pool != NULL)
00265             con->pool->nb_opened--;
00266 
00267         con->cstate = OCI_CONN_ALLOCATED;
00268     }
00269 
00270     return res;
00271 }
00272 
00273 /* --------------------------------------------------------------------------------------------- *
00274  * OCI_ConnectionLogon
00275  * --------------------------------------------------------------------------------------------- */
00276 
00277 boolean OCI_ConnectionLogon
00278 (
00279     OCI_Connection *con,
00280     const mtext    *new_pwd,
00281     const mtext    *tag
00282 )
00283 {
00284     void *ostr  = NULL;
00285     int osize   = -1;
00286     boolean res = TRUE;
00287 
00288     OCI_CHECK(con == NULL, FALSE);
00289 
00290     #if OCI_VERSION_COMPILE < OCI_9_2
00291 
00292     OCI_NOT_USED(tag)
00293 
00294     #endif
00295 
00296     #if OCI_VERSION_COMPILE >= OCI_9_2
00297 
00298     if (con->pool == NULL)
00299     {
00300 
00301     #endif
00302 
00303     /* allocate session handle */
00304 
00305     if (res == TRUE)
00306         res = (OCI_SUCCESS == OCI_HandleAlloc((dvoid *) OCILib.env,
00307                                               (dvoid **) (void *) &con->ses,
00308                                               (ub4) OCI_HTYPE_SESSION,
00309                                               (size_t) 0, (dvoid **) NULL));
00310 
00311     /* allocate context handle */
00312 
00313     if (res == TRUE)
00314         res = (OCI_SUCCESS == OCI_HandleAlloc((dvoid *) OCILib.env,
00315                                               (dvoid **) (void *) &con->cxt,
00316                                               (ub4) OCI_HTYPE_SVCCTX,
00317                                               (size_t) 0, (dvoid **) NULL));
00318 
00319     /* set context server attribute */
00320 
00321     OCI_CALL2
00322     (
00323         res, con,
00324 
00325         OCIAttrSet((dvoid *) con->cxt, (ub4) OCI_HTYPE_SVCCTX,
00326                    (dvoid *) con->svr, (ub4) sizeof (con->svr),
00327                    (ub4) OCI_ATTR_SERVER, con->err)
00328     )
00329 
00330     /* modifiy user password if needed */
00331 
00332     if (new_pwd && new_pwd[0])
00333     {
00334 
00335         OCI_CALL2
00336         (
00337             res, con,
00338 
00339             OCIAttrSet((dvoid *) con->cxt, (ub4) OCI_HTYPE_SVCCTX,
00340                        (dvoid *) con->ses, (ub4) sizeof(con->ses),
00341                        (ub4) OCI_ATTR_SESSION, con->err)
00342         )
00343 
00344         OCI_CALL2
00345         (
00346             res, con,
00347 
00348             OCIPasswordChange(con->cxt, con->err,
00349                               (OraText *) con->user, (ub4) mtslen(con->user),
00350                               (OraText *) con->pwd,  (ub4) mtslen(con->pwd),
00351                               (OraText *) new_pwd,   (ub4) mtslen(new_pwd),
00352                               OCI_AUTH)
00353         )
00354 
00355         if (res == TRUE)
00356         {
00357             OCI_FREE(con->pwd);
00358 
00359             con->pwd = mtsdup(new_pwd);
00360         }
00361     }
00362     else
00363     {
00364         /* set session login attribute */
00365 
00366         if ((res == TRUE) && (con->user != NULL) && (con->user[0] != 0))
00367         {
00368             osize = -1;
00369             ostr  = OCI_GetInputMetaString(con->user, &osize);
00370 
00371             OCI_CALL2
00372             (
00373                 res, con,
00374 
00375                 OCIAttrSet((dvoid *) con->ses,(ub4)  OCI_HTYPE_SESSION,
00376                            (dvoid *) ostr, (ub4) osize,
00377                            (ub4) OCI_ATTR_USERNAME, con->err)
00378             )
00379 
00380             OCI_ReleaseMetaString(ostr);
00381         }
00382 
00383         /* set session password attribute */
00384 
00385         if ((res == TRUE) && (con->pwd != NULL) && (con->pwd[0] != 0))
00386         {
00387             osize = -1;
00388             ostr  = OCI_GetInputMetaString(con->pwd, &osize);
00389 
00390             OCI_CALL2
00391             (
00392                 res, con,
00393 
00394                 OCIAttrSet((dvoid *) con->ses, (ub4) OCI_HTYPE_SESSION,
00395                            (dvoid *) ostr, (ub4) osize,
00396                            (ub4) OCI_ATTR_PASSWORD, con->err)
00397             )
00398 
00399             OCI_ReleaseMetaString(ostr);
00400         }
00401 
00402         /* start session */
00403 
00404         if (res == TRUE)
00405         {
00406             ub4 credt = OCI_CRED_RDBMS;
00407 
00408             if  (((con->user == NULL) || (con->user[0] == 0)) &&
00409                  ((con->pwd  == NULL) || (con->pwd[0]  == 0)))
00410             {
00411                 credt = OCI_CRED_EXT;
00412             }
00413 
00414             OCI_CALL2
00415             (
00416                 res, con,
00417 
00418                 OCISessionBegin(con->cxt, con->err, con->ses, credt, con->mode)
00419             )
00420 
00421             /* This call has moved after OCISessionBegin() call to
00422                enable connection pooling (an error ORA-24324 was thrown if
00423                the session handle was set to the service context handle
00424                before OCISessionBegin()
00425 
00426                note  : from v3.7.0, OCISessionBegin() is not used anymore
00427                        for OCI managed pools
00428                */
00429 
00430             OCI_CALL2
00431             (
00432                 res, con,
00433 
00434                 OCIAttrSet((dvoid *) con->cxt, (ub4) OCI_HTYPE_SVCCTX,
00435                            (dvoid *) con->ses, (ub4) sizeof(con->ses),
00436                            (ub4) OCI_ATTR_SESSION, con->err)
00437             )
00438         }
00439     }
00440 
00441     #if OCI_VERSION_COMPILE >= OCI_9_2
00442 
00443 }
00444 else
00445 {
00446     if (OCILib.version_runtime >= OCI_9_0)
00447     {
00448 
00449         ub4 mode       = OCI_DEFAULT;
00450         boolean found  = FALSE;
00451         void *ostr_tag = NULL;
00452         int osize_tag  = 0;
00453 
00454         OraText *ostr_ret = NULL;
00455         ub4 osize_ret     = 0;
00456 
00457         osize = -1;
00458         ostr  = OCI_GetInputMetaString(con->pool->name, &osize);
00459 
00460         if (con->pool->htype == OCI_HTYPE_CPOOL)
00461         {
00462             mode = OCI_SESSGET_CPOOL;
00463         }
00464         else
00465         {
00466             mode = OCI_SESSGET_SPOOL;
00467 
00468             if (tag != NULL)
00469             {
00470                 osize_tag = -1;
00471                 ostr_tag  = OCI_GetInputMetaString(tag, &osize_tag);
00472             }
00473         }
00474 
00475         OCI_CALL2
00476         (
00477             res, con,
00478 
00479             OCISessionGet(OCILib.env, con->err, &con->cxt, con->pool->authp,
00480                           (dvoid *) ostr, (ub4) osize, ostr_tag, osize_tag,
00481                           &ostr_ret, &osize_ret, &found, mode)
00482         )
00483 
00484         if (res == TRUE)
00485         {
00486             con->ses = (OCISession *) con->pool->authp;
00487 
00488             if (found == TRUE)
00489             {
00490                 OCI_SetSessionTag(con, tag);
00491             }
00492         }
00493     }
00494 }
00495 
00496     #endif
00497 
00498     /* check for success */
00499 
00500     if (res == TRUE)
00501     {
00502         /* get server version */
00503 
00504         OCI_GetVersionServer(con);
00505 
00506         if (!(con->mode & OCI_PRELIM_AUTH))
00507         {
00508             /* create default transaction object */
00509 
00510             con->trs = OCI_TransactionCreate(con, 1, OCI_TRANS_READWRITE, NULL);
00511 
00512             /* start transaction */
00513 
00514             res = OCI_TransactionStart(con->trs);
00515         }
00516     }
00517 
00518     /* set OCILIB's driver layer name attribute */
00519 
00520     #if OCI_VERSION_COMPILE >= OCI_11_1
00521 
00522     if ((res == TRUE) && (OCILib.version_runtime >= OCI_11_1) && (con->ver_num >= OCI_11_1))
00523     {
00524         osize = -1;
00525         ostr  = OCI_GetInputMetaString(OCILIB_DRIVER_NAME, &osize);
00526 
00527         OCI_CALL2
00528         (
00529             res, con,
00530 
00531             OCIAttrSet((dvoid *) con->ses, (ub4) OCI_HTYPE_SESSION,
00532                        (dvoid *) ostr, (ub4) osize,
00533                        (ub4) OCI_ATTR_DRIVER_NAME, con->err)
00534         )
00535 
00536         OCI_ReleaseMetaString(ostr);
00537     }
00538 
00539     #endif
00540 
00541     /* update internal status */
00542 
00543     if (res == TRUE)
00544     {
00545         if (OCILib.version_runtime < OCI_9_0 && con->pool != NULL)
00546             con->pool->nb_busy++;
00547 
00548         con->cstate = OCI_CONN_LOGGED;
00549     }
00550 
00551     return res;
00552 }
00553 
00554 /* --------------------------------------------------------------------------------------------- *
00555  * OCI_ConnectionLogOff
00556  * --------------------------------------------------------------------------------------------- */
00557 
00558 boolean OCI_ConnectionLogOff
00559 (
00560     OCI_Connection *con
00561 )
00562 {
00563     boolean res = TRUE;
00564 
00565     OCI_CHECK(con == NULL, FALSE);
00566     OCI_CHECK(con->cstate != OCI_CONN_LOGGED, FALSE);
00567 
00568     /* deassociate connection from existing subscriptions */
00569 
00570     OCI_SubscriptionDetachConnection(con);
00571 
00572     /* free all statements */
00573 
00574     OCI_ListForEach(con->stmts, (POCI_LIST_FOR_EACH) OCI_StatementClose);
00575     OCI_ListClear(con->stmts);
00576 
00577     /* free all transactions */
00578 
00579     OCI_ListForEach(con->trsns, (POCI_LIST_FOR_EACH) OCI_TransactionClose);
00580     OCI_ListClear(con->trsns);
00581 
00582     /* free all type info objects */
00583 
00584     OCI_ListForEach(con->tinfs, (POCI_LIST_FOR_EACH) OCI_TypeInfoClose);
00585     OCI_ListClear(con->tinfs);
00586 
00587     /* close opened files */
00588 
00589     if (con->nb_files > 0)
00590     {
00591         OCILobFileCloseAll(con->cxt, con->err);
00592     }
00593 
00594     /* close session */
00595 
00596     #if OCI_VERSION_COMPILE >= OCI_9_2
00597 
00598     if (con->pool == NULL)
00599     {
00600 
00601     #endif
00602 
00603     /* close any server files not explicitly closed - no check of return code */
00604 
00605     if ((con->cxt != NULL) && (con->err != NULL) && (con->ses != NULL))
00606     {
00607         OCI_CALL2
00608         (
00609             res, con,
00610 
00611             OCISessionEnd(con->cxt, con->err, con->ses, (ub4) OCI_DEFAULT)
00612         )
00613 
00614         /* close session handle */
00615 
00616         if (con->ses != NULL)
00617         {
00618             OCI_HandleFree((dvoid *) con->ses, (ub4) OCI_HTYPE_SESSION);
00619 
00620             con->ses = NULL;
00621         }
00622 
00623         /* close context handle */
00624 
00625         if (con->cxt != NULL)
00626         {
00627             OCI_HandleFree((dvoid *) con->cxt, (ub4) OCI_HTYPE_SVCCTX);
00628 
00629             con->cxt = NULL;
00630         }
00631     }
00632 
00633     #if OCI_VERSION_COMPILE >= OCI_9_2
00634 
00635 }
00636 else
00637 {
00638     if (OCILib.version_runtime >= OCI_9_0)
00639     {
00640         void *ostr = NULL;
00641         int osize  = 0;
00642         ub4 mode   = OCI_DEFAULT;
00643 
00644         if ((con->sess_tag != NULL) && (con->pool->htype == (ub4) OCI_HTYPE_SPOOL))
00645         {
00646             osize = -1;
00647             ostr  = OCI_GetInputMetaString(con->sess_tag, &osize);
00648             mode  = OCI_SESSRLS_RETAG;
00649         }
00650 
00651         /* set context transaction attribute to NULL
00652            If not done, OCISessionRelease() genarates a segfault if
00653            a transaction to set on the service context handle
00654 
00655            Once again, OCI bug ? Need to report that on metalink ...
00656         */
00657 
00658         OCI_CALL2
00659         (
00660             res, con,
00661 
00662             OCIAttrSet((dvoid *) con->cxt, (ub4) OCI_HTYPE_SVCCTX,
00663                        (dvoid *) NULL, (ub4) 0,
00664                        (ub4) OCI_ATTR_TRANS,con->err)
00665         )
00666 
00667         OCI_CALL2
00668         (
00669             res, con,
00670 
00671             OCISessionRelease(con->cxt, con->err, ostr, (ub4) osize, mode)
00672         )
00673 
00674         con->cxt = NULL;
00675     }
00676 }
00677 
00678     #endif
00679 
00680     /* update internal status */
00681 
00682     if (res == TRUE)
00683     {
00684         con->cstate = OCI_CONN_ATTACHED;
00685 
00686         if (OCILib.version_runtime < OCI_9_0 && con->pool != NULL)
00687             con->pool->nb_busy--;
00688     }
00689 
00690     return res;
00691 }
00692 
00693 /* --------------------------------------------------------------------------------------------- *
00694  * OCI_ConnectionClose
00695  * --------------------------------------------------------------------------------------------- */
00696 
00697 boolean OCI_ConnectionClose
00698 (
00699     OCI_Connection *con
00700 )
00701 {
00702     OCI_CHECK(con == NULL, FALSE);
00703 
00704     /* clear server output resources */
00705 
00706     OCI_ServerDisableOutput(con);
00707 
00708     /* lofoff and detatch form server */
00709 
00710     OCI_ConnectionLogOff(con);
00711     OCI_ConnectionDetach(con);
00712     OCI_ConnectionDeallocate(con);
00713 
00714     /* free internal lists */
00715 
00716     OCI_ListFree(con->stmts);
00717     OCI_ListFree(con->trsns);
00718     OCI_ListFree(con->tinfs);
00719 
00720     if (con->pool == NULL)
00721     {
00722         /* free strings */
00723 
00724         OCI_FREE(con->db);
00725         OCI_FREE(con->user);
00726         OCI_FREE(con->pwd);
00727     }
00728 
00729     OCI_FREE(con->fmt_date);
00730     OCI_FREE(con->fmt_num);
00731     OCI_FREE(con->ver_str);
00732     OCI_FREE(con->sess_tag);
00733 
00734     con->stmts = NULL;
00735     con->trsns = NULL;
00736     con->tinfs = NULL;
00737 
00738     return TRUE;
00739 }
00740 
00741 /* ********************************************************************************************* *
00742  *                             PUBLIC FUNCTIONS
00743  * ********************************************************************************************* */
00744 
00745 /* --------------------------------------------------------------------------------------------- *
00746  * OCI_ConnectionCreate
00747  * --------------------------------------------------------------------------------------------- */
00748 
00749 OCI_Connection * OCI_API OCI_ConnectionCreate
00750 (
00751     const mtext *db,
00752     const mtext *user,
00753     const mtext *pwd,
00754     unsigned int mode
00755 )
00756 {
00757     OCI_Connection * con;
00758 
00759     /* let's be sure OCI_Initialize() has been called */
00760 
00761     OCI_CHECK_INITIALIZED(NULL);
00762 
00763     con = OCI_ConnectionAllocate(NULL, db, user, pwd, mode);
00764 
00765     if (con != NULL)
00766     {
00767         if (OCI_ConnectionAttach(con)            == FALSE ||
00768             OCI_ConnectionLogon(con, NULL, NULL) == FALSE)
00769         {
00770             OCI_ConnectionFree(con);
00771             con = NULL;
00772         }
00773     }
00774 
00775     OCI_RESULT(con != NULL);
00776 
00777     return con;
00778 }
00779 
00780 /* --------------------------------------------------------------------------------------------- *
00781  * OCI_ConnectionFree
00782  * --------------------------------------------------------------------------------------------- */
00783 
00784 boolean OCI_API OCI_ConnectionFree
00785 (
00786     OCI_Connection *con
00787 )
00788 {
00789     boolean res    = TRUE;
00790     OCI_Error *err = NULL;
00791 
00792     OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, FALSE);
00793 
00794     /* clear connection reference from current error object */
00795 
00796     err = OCI_ErrorGet(FALSE, FALSE);
00797 
00798     if (err != NULL && err->con == con)
00799         err->con = NULL;
00800 
00801     OCI_FREE(con->sess_tag);
00802 
00803     if (con->pool != NULL)
00804     {
00805         res = OCI_ConnectionLogOff(con);
00806 
00807         if (OCILib.version_runtime >= OCI_9_0)
00808             OCI_ConnectionDetach(con);
00809     }
00810     else
00811     {
00812         res = OCI_ConnectionClose(con);
00813         OCI_ListRemove(OCILib.cons, con);
00814         OCI_FREE(con);
00815     }
00816 
00817     OCI_RESULT(res);
00818 
00819     return res;
00820 }
00821 
00822 /* --------------------------------------------------------------------------------------------- *
00823  * OCI_Commit
00824  * --------------------------------------------------------------------------------------------- */
00825 
00826 boolean OCI_API OCI_Commit
00827 (
00828     OCI_Connection *con
00829 )
00830 {
00831     boolean res = TRUE;
00832 
00833     OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, FALSE);
00834 
00835     OCI_CALL2
00836     (
00837         res, con,
00838 
00839         OCITransCommit(con->cxt, con->err, (ub4) OCI_DEFAULT)
00840     )
00841 
00842     OCI_RESULT(res);
00843 
00844     return res;
00845 }
00846 
00847 /* --------------------------------------------------------------------------------------------- *
00848  * OCI_Rollback
00849  * --------------------------------------------------------------------------------------------- */
00850 
00851 boolean OCI_API OCI_Rollback
00852 (
00853     OCI_Connection *con
00854 )
00855 {
00856     boolean res = TRUE;
00857 
00858     OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, FALSE);
00859 
00860     OCI_CALL2
00861     (
00862         res, con,
00863 
00864         OCITransRollback(con->cxt, con->err, (ub4) OCI_DEFAULT)
00865     )
00866 
00867     OCI_RESULT(res);
00868 
00869     return res;
00870 }
00871 
00872 /* --------------------------------------------------------------------------------------------- *
00873  * OCI_SetAutoCommit
00874  * --------------------------------------------------------------------------------------------- */
00875 
00876 boolean OCI_API OCI_SetAutoCommit
00877 (
00878     OCI_Connection *con,
00879     boolean         enable
00880 )
00881 {
00882     OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, FALSE);
00883 
00884     OCI_RESULT(TRUE);
00885 
00886     con->autocom = enable;
00887 
00888     return TRUE;
00889 }
00890 
00891 /* --------------------------------------------------------------------------------------------- *
00892  * OCI_GetAutoCommit
00893  * --------------------------------------------------------------------------------------------- */
00894 
00895 boolean OCI_API OCI_GetAutoCommit
00896 (
00897     OCI_Connection *con
00898 )
00899 {
00900     OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, FALSE);
00901 
00902     OCI_RESULT(TRUE);
00903 
00904     return con->autocom;
00905 }
00906 
00907 /* --------------------------------------------------------------------------------------------- *
00908  * OCI_IsConnected
00909  * --------------------------------------------------------------------------------------------- */
00910 
00911 boolean OCI_API OCI_IsConnected
00912 (
00913     OCI_Connection *con
00914 )
00915 {
00916     boolean res = TRUE;
00917     ub4 status  = 0;
00918     ub4 size    = (ub4) sizeof(status);
00919 
00920     OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, FALSE);
00921 
00922     OCI_CALL2
00923     (
00924         res, con,
00925 
00926         OCIAttrGet((dvoid **) con->svr, (ub4) OCI_HTYPE_SERVER,
00927                    (dvoid *) &status, (ub4 *) &size,
00928                    (ub4) OCI_ATTR_SERVER_STATUS, con->err)
00929 
00930     )
00931 
00932     OCI_RESULT(res);
00933 
00934     return (status == OCI_SERVER_NORMAL);
00935 }
00936 
00937 /* --------------------------------------------------------------------------------------------- *
00938  * OCI_GetUserData
00939  * --------------------------------------------------------------------------------------------- */
00940 
00941 void * OCI_API OCI_GetUserData
00942 (
00943     OCI_Connection *con
00944 )
00945 {
00946     OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, NULL);
00947 
00948     OCI_RESULT(TRUE);
00949 
00950     return con->usrdata;
00951 }
00952 
00953 /* --------------------------------------------------------------------------------------------- *
00954  * OCI_SetSetData
00955  * --------------------------------------------------------------------------------------------- */
00956 
00957 boolean OCI_API OCI_SetUserData
00958 (
00959     OCI_Connection *con,
00960     void           *data
00961 )
00962 {
00963     OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, FALSE);
00964 
00965     OCI_RESULT(TRUE);
00966 
00967     con->usrdata = data;
00968 
00969     return TRUE;
00970 }
00971 
00972 /* --------------------------------------------------------------------------------------------- *
00973  * OCI_SetSessionTag
00974  * --------------------------------------------------------------------------------------------- */
00975 
00976 boolean OCI_API OCI_SetSessionTag
00977 (
00978     OCI_Connection *con,
00979     const mtext    *tag
00980 )
00981 {
00982     boolean res = TRUE;
00983 
00984     OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, FALSE);
00985 
00986     OCI_RESULT(TRUE);
00987 
00988     OCI_FREE(con->sess_tag);
00989 
00990     #if OCI_VERSION_COMPILE >= OCI_9_2
00991 
00992     if ((tag              != NULL                 ) &&
00993         (con->pool        != NULL                 ) &&
00994         (con->pool->htype == (ub4) OCI_HTYPE_SPOOL))
00995     {
00996         con->sess_tag = mtsdup(tag);
00997 
00998         res = (con->sess_tag != NULL);
00999     }
01000 
01001     #else
01002 
01003     OCI_NOT_USED(tag)
01004 
01005     #endif
01006 
01007     OCI_RESULT(res);
01008 
01009     return res;
01010 }
01011 
01012 /* --------------------------------------------------------------------------------------------- *
01013  * OCI_GetUserData
01014  * OCI_GetSessionTag */
01015 
01016 const mtext * OCI_API OCI_GetSessionTag
01017 (
01018     OCI_Connection *con
01019 )
01020 {
01021     OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, NULL);
01022 
01023     OCI_RESULT(TRUE);
01024 
01025     return con->sess_tag;
01026 }
01027 
01028 /* --------------------------------------------------------------------------------------------- *
01029  * OCI_GetDatabase
01030  * --------------------------------------------------------------------------------------------- */
01031 
01032 const mtext * OCI_API OCI_GetDatabase
01033 (
01034     OCI_Connection *con
01035 )
01036 {
01037     OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, NULL);
01038 
01039     OCI_RESULT(TRUE);
01040 
01041     return (const mtext *) con->db;
01042 }
01043 
01044 /* --------------------------------------------------------------------------------------------- *
01045  * OCI_GetUserName
01046  * --------------------------------------------------------------------------------------------- */
01047 
01048 const mtext * OCI_API OCI_GetUserName
01049 (
01050     OCI_Connection *con
01051 )
01052 {
01053     OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, NULL);
01054 
01055     OCI_RESULT(TRUE);
01056 
01057     return (const mtext *) con->user;
01058 }
01059 
01060 /* --------------------------------------------------------------------------------------------- *
01061  * OCI_GetPassword
01062  * --------------------------------------------------------------------------------------------- */
01063 
01064 const mtext * OCI_API OCI_GetPassword
01065 (
01066     OCI_Connection *con
01067 )
01068 {
01069     OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, NULL);
01070 
01071     OCI_RESULT(TRUE);
01072 
01073     return (const mtext *) con->pwd;
01074 }
01075 
01076 /* --------------------------------------------------------------------------------------------- *
01077  * OCI_SetPassword
01078  * --------------------------------------------------------------------------------------------- */
01079 
01080 boolean OCI_API OCI_SetPassword
01081 (
01082     OCI_Connection *con,
01083     const mtext    *password
01084 )
01085 {
01086     boolean res = TRUE;
01087     ub4 mode    = OCI_DEFAULT;
01088 
01089     OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, FALSE);
01090     OCI_CHECK_PTR(OCI_IPC_STRING, password, FALSE);
01091 
01092     if (con->cstate != OCI_CONN_LOGGED)
01093     {
01094         OCI_ConnectionLogon(con, password, NULL);
01095     }
01096     else
01097     {
01098         OCI_CALL2
01099         (
01100             res, con,
01101 
01102             OCIPasswordChange(con->cxt, con->err,
01103                               (OraText *) con->user, (ub4) mtslen(con->user),
01104                               (OraText *) con->pwd,  (ub4) mtslen(con->pwd),
01105                               (OraText *) password,  (ub4) mtslen(password),
01106                               mode)
01107         )
01108     }
01109 
01110     OCI_RESULT(res);
01111 
01112     return res;
01113 }
01114 
01115 /* --------------------------------------------------------------------------------------------- *
01116  * OCI_SetUserPassword
01117  * --------------------------------------------------------------------------------------------- */
01118 
01119 boolean OCI_API OCI_SetUserPassword
01120 (
01121     const mtext *db,
01122     const mtext *user,
01123     const mtext *pwd,
01124     const mtext *new_pwd
01125 )
01126 {
01127     OCI_Connection * con = NULL;
01128     boolean res          = FALSE;
01129 
01130     /* let's be sure OCI_Initialize() has been called */
01131 
01132     OCI_CHECK_INITIALIZED(FALSE);
01133 
01134     con = OCI_ConnectionAllocate(NULL, db, user, pwd, OCI_AUTH);
01135 
01136     if (con != NULL)
01137     {
01138         if (OCI_ConnectionAttach(con)               == FALSE ||
01139             OCI_ConnectionLogon(con, new_pwd, NULL) == FALSE)
01140         {
01141             OCI_ConnectionFree(con);
01142             con = NULL;
01143         }
01144     }
01145 
01146     if (con != NULL)
01147     {
01148         res = TRUE;
01149         OCI_ConnectionFree(con);
01150     }
01151     else
01152         res = FALSE;
01153 
01154     OCI_RESULT(res);
01155 
01156     return res;
01157 }
01158 
01159 /* --------------------------------------------------------------------------------------------- *
01160  * OCI_GetSessionMode
01161  * --------------------------------------------------------------------------------------------- */
01162 
01163 unsigned int OCI_API OCI_GetSessionMode
01164 (
01165     OCI_Connection *con
01166 )
01167 {
01168     OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, OCI_UNKNOWN);
01169 
01170     OCI_RESULT(TRUE);
01171 
01172     return con->mode;
01173 }
01174 
01175 /* --------------------------------------------------------------------------------------------- *
01176  * OCI_GetVersionServer
01177  * --------------------------------------------------------------------------------------------- */
01178 
01179 const mtext * OCI_API OCI_GetVersionServer
01180 (
01181     OCI_Connection *con
01182 )
01183 {
01184     boolean res = TRUE;
01185 
01186     OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, NULL);
01187 
01188     /* no version available in prelim mode */
01189 
01190     if ((con->ver_str == NULL) && (!(con->mode & OCI_PRELIM_AUTH)))
01191     {
01192         res = FALSE;
01193 
01194         con->ver_str = (mtext *) OCI_MemAlloc(OCI_IPC_STRING, sizeof(mtext),
01195                                               (size_t) (OCI_SIZE_BUFFER + 1),
01196                                               FALSE);
01197 
01198         if (con->ver_str != NULL)
01199         {
01200             int osize  = OCI_SIZE_BUFFER * (int) sizeof(mtext);
01201             void *ostr = NULL;
01202             mtext *p   = NULL;
01203 
01204             con->ver_str[0] = 0;
01205 
01206             res = TRUE;
01207 
01208             ostr = OCI_GetInputMetaString(con->ver_str, &osize);
01209 
01210             OCI_CALL2
01211             (
01212                 res, con,
01213 
01214                 OCIServerVersion((dvoid *) con->cxt, con->err,
01215                                  (OraText *) ostr, (ub4) osize,
01216                                  (ub1) OCI_HTYPE_SVCCTX)
01217             )
01218 
01219             OCI_GetOutputMetaString(ostr, con->ver_str, &osize);
01220 
01221             OCI_ReleaseMetaString(ostr);
01222 
01223             if (res == TRUE)
01224             {
01225                 int ver_maj, ver_min, ver_rev;
01226 
01227                 ver_maj = ver_min = ver_rev = 0;
01228 
01229                 con->ver_str[osize / (int) sizeof(mtext)] = 0;
01230 
01231                 /* parse server version string to find the version information
01232                  **/
01233 
01234                 for (p = con->ver_str; (p != NULL) && (*p != 0); p++)
01235                 {
01236                     if (mtisdigit(*p) &&
01237                         (*(p + (size_t) 1) != 0) &&
01238                         (*(p + (size_t) 1) == MT('.') || (*(p + (size_t) 2) == MT('.') )))
01239                     {
01240                         if (OCI_NB_ARG_VERSION == mtsscanf(p, MT("%d.%d.%d"),
01241                                                            (int *) &ver_maj,
01242                                                            (int *) &ver_min,
01243                                                            (int *) &ver_rev))
01244                         {
01245                             con->ver_num = ver_maj*100 + ver_min*10 + ver_rev;
01246                         }
01247 
01248                         break;
01249                     }
01250                 }
01251             }
01252             else
01253                 OCI_FREE(con->ver_str);
01254         }
01255     }
01256 
01257     OCI_RESULT(res);
01258 
01259     return con->ver_str;
01260 }
01261 
01262 /* --------------------------------------------------------------------------------------------- *
01263  * OCI_GetServerMajorVersion
01264  * --------------------------------------------------------------------------------------------- */
01265 
01266 unsigned int OCI_API OCI_GetServerMajorVersion
01267 (
01268     OCI_Connection *con
01269 )
01270 {
01271     OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, OCI_UNKNOWN);
01272 
01273     if (con->ver_num == OCI_UNKNOWN)
01274         OCI_GetVersionServer(con);
01275 
01276     OCI_RESULT(con->ver_num != OCI_UNKNOWN);
01277 
01278     return (unsigned int) OCI_VER_MAJ(con->ver_num);
01279 }
01280 
01281 /* --------------------------------------------------------------------------------------------- *
01282  * OCI_GetServerMinorVersion
01283  * --------------------------------------------------------------------------------------------- */
01284 
01285 unsigned int OCI_API OCI_GetServerMinorVersion
01286 (
01287     OCI_Connection *con
01288 )
01289 {
01290     OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, OCI_UNKNOWN);
01291 
01292     if (con->ver_num == OCI_UNKNOWN)
01293         OCI_GetVersionServer(con);
01294 
01295     OCI_RESULT(con->ver_num != OCI_UNKNOWN);
01296 
01297     return OCI_VER_MIN(con->ver_num);
01298 }
01299 
01300 /* --------------------------------------------------------------------------------------------- *
01301  * OCI_GetServerRevisionVersion
01302  * --------------------------------------------------------------------------------------------- */
01303 
01304 unsigned int OCI_API OCI_GetServerRevisionVersion
01305 (
01306     OCI_Connection *con
01307 )
01308 {
01309     OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, OCI_UNKNOWN);
01310 
01311     if (con->ver_num == OCI_UNKNOWN)
01312         OCI_GetVersionServer(con);
01313 
01314     OCI_RESULT(con->ver_num != OCI_UNKNOWN);
01315 
01316     return (unsigned int) OCI_VER_MAJ(con->ver_num);
01317 }
01318 
01319 /* --------------------------------------------------------------------------------------------- *
01320  * OCI_GetTransaction
01321  * --------------------------------------------------------------------------------------------- */
01322 
01323 OCI_Transaction * OCI_API OCI_GetTransaction
01324 (
01325     OCI_Connection *con
01326 )
01327 {
01328     OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, NULL);
01329 
01330     OCI_RESULT(TRUE);
01331 
01332     return con->trs;
01333 }
01334 
01335 /* --------------------------------------------------------------------------------------------- *
01336  * OCI_SetTransaction
01337  * --------------------------------------------------------------------------------------------- */
01338 
01339 boolean OCI_API OCI_SetTransaction
01340 (
01341     OCI_Connection  *con,
01342     OCI_Transaction *trans
01343 )
01344 {
01345     boolean res = TRUE;
01346 
01347     OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, FALSE);
01348     OCI_CHECK_PTR(OCI_IPC_TRANSACTION, trans, FALSE);
01349 
01350     res = OCI_TransactionStop(con->trs);
01351 
01352     if (res == TRUE)
01353         con->trs = trans;
01354 
01355     OCI_RESULT(res);
01356 
01357     return res;
01358 }
01359 
01360 /* --------------------------------------------------------------------------------------------- *
01361  * OCI_GetVersionConnection
01362  * --------------------------------------------------------------------------------------------- */
01363 
01364 unsigned int OCI_API OCI_GetVersionConnection
01365 (
01366     OCI_Connection *con
01367 )
01368 {
01369     int v1, v2;
01370 
01371     OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, OCI_UNKNOWN);
01372 
01373     v1 = OCI_GetOCIRuntimeVersion();
01374     v2 = OCI_GetServerMajorVersion(con);
01375 
01376     OCI_RESULT(TRUE);
01377 
01378     /* return the minimum supported version */
01379 
01380     return (OCILib.version_runtime > con->ver_num) ? con->ver_num : OCILib.version_runtime;
01381 }
01382 
01383 /* --------------------------------------------------------------------------------------------- *
01384  * OCI_SetDefaultFormatDate
01385  * --------------------------------------------------------------------------------------------- */
01386 
01387 boolean OCI_API OCI_SetDefaultFormatDate
01388 (
01389     OCI_Connection *con,
01390     const mtext    *format
01391 )
01392 {
01393     boolean res = TRUE;
01394 
01395     OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, FALSE);
01396 
01397     OCI_FREE(con->fmt_date);
01398 
01399     con->fmt_date = mtsdup(format ? format : OCI_STRING_FORMAT_DATE);
01400 
01401     res = (con->fmt_date != NULL);
01402 
01403     OCI_RESULT(res);
01404 
01405     return res;
01406 }
01407 
01408 /* --------------------------------------------------------------------------------------------- *
01409  * OCI_GetDefaultFormatDate
01410  * --------------------------------------------------------------------------------------------- */
01411 
01412 const mtext * OCI_API OCI_GetDefaultFormatDate
01413 (
01414     OCI_Connection *con
01415 )
01416 {
01417     OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, NULL);
01418 
01419     OCI_RESULT(TRUE);
01420 
01421     if (con->fmt_date == NULL)
01422         OCI_SetDefaultFormatDate(con, NULL);
01423 
01424     return (con->fmt_date);
01425 }
01426 
01427 /* --------------------------------------------------------------------------------------------- *
01428  * OCI_SetDefaultFormatNumeric
01429  * --------------------------------------------------------------------------------------------- */
01430 
01431 boolean OCI_API OCI_SetDefaultFormatNumeric
01432 (
01433     OCI_Connection *con,
01434     const mtext    *format
01435 )
01436 {
01437     boolean res = TRUE;
01438 
01439     OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, FALSE);
01440 
01441     OCI_FREE(con->fmt_num);
01442 
01443     con->fmt_num = mtsdup(format ? format : OCI_STRING_FORMAT_NUM);
01444 
01445     res = (con->fmt_num != NULL);
01446 
01447     OCI_RESULT(res);
01448 
01449     return res;
01450 }
01451 
01452 /* --------------------------------------------------------------------------------------------- *
01453  * OCI_GetDefaultFormatNumeric
01454  * --------------------------------------------------------------------------------------------- */
01455 
01456 const mtext * OCI_API OCI_GetDefaultFormatNumeric
01457 (
01458     OCI_Connection *con
01459 )
01460 {
01461     OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, NULL);
01462 
01463     OCI_RESULT(TRUE);
01464 
01465     if (con->fmt_num == NULL)
01466         OCI_SetDefaultFormatNumeric(con, NULL);
01467 
01468     return (con->fmt_num);
01469 }
01470 
01471 /* --------------------------------------------------------------------------------------------- *
01472  * OCI_Break
01473  * --------------------------------------------------------------------------------------------- */
01474 
01475 boolean OCI_API OCI_Break
01476 (
01477     OCI_Connection *con
01478 )
01479 {
01480     boolean res = TRUE;
01481 
01482     OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, FALSE);
01483 
01484     OCI_CALL2
01485     (
01486         res, con,
01487 
01488         OCIBreak((dvoid *) con->cxt, con->err)
01489     )
01490 
01491     OCI_RESULT(res);
01492 
01493     return res;
01494 }
01495 
01496 /* --------------------------------------------------------------------------------------------- *
01497  * OCI_ServerEnableOutput
01498  * --------------------------------------------------------------------------------------------- */
01499 
01500 boolean OCI_API OCI_ServerEnableOutput
01501 (
01502     OCI_Connection *con,
01503     unsigned int    bufsize,
01504     unsigned int    arrsize,
01505     unsigned int    lnsize
01506 )
01507 {
01508     boolean res = TRUE;
01509 
01510     OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, FALSE);
01511 
01512     /* initialize the output buffer on server side */
01513 
01514     if (con->svopt == NULL)
01515     {
01516         con->svopt = (OCI_ServerOutput *) OCI_MemAlloc(OCI_IPC_SERVER_OUPUT,
01517                                                        sizeof(*con->svopt),
01518                                                        (size_t) 1, TRUE);
01519 
01520         res = (con->svopt != NULL);
01521     }
01522 
01523     /* allocation internal buffer if needed */
01524 
01525     if ((res == TRUE) && (con->svopt->arrbuf == NULL))
01526     {
01527         unsigned int charsize = sizeof(dtext);
01528 
01529         /* check params ranges ( Oracle 10g increased the size of output line */
01530 
01531         if (con->ver_num >= OCI_10_2)
01532         {
01533             if (lnsize < OCI_OUPUT_LSIZE)
01534                 lnsize = OCI_OUPUT_LSIZE;
01535             else if (lnsize > OCI_OUPUT_LSIZE_10G)
01536                 lnsize = OCI_OUPUT_LSIZE_10G;
01537         }
01538         else
01539         {
01540             if (lnsize > OCI_OUPUT_LSIZE)
01541                 lnsize = OCI_OUPUT_LSIZE;
01542         }
01543 
01544         con->svopt->arrsize = arrsize;
01545         con->svopt->lnsize  = lnsize;
01546 
01547         /* allocate internal string (line) array */
01548 
01549         con->svopt->arrbuf =
01550 
01551             (ub1 *) OCI_MemAlloc(OCI_IPC_STRING,
01552                                  ((size_t)(con->svopt->lnsize + 1)) * charsize,
01553                                  (size_t) con->svopt->arrsize, TRUE);
01554 
01555         res = (con->svopt->arrbuf != NULL);
01556     }
01557 
01558     if (res == TRUE)
01559     {
01560         if (con->svopt->stmt == NULL)
01561             con->svopt->stmt = OCI_StatementCreate(con);
01562 
01563         if (con->svopt->stmt != NULL)
01564         {
01565             /* enable server ouput */
01566 
01567             res = OCI_Prepare(con->svopt->stmt,
01568                               MT("BEGIN DBMS_OUTPUT.ENABLE(:n); END;"));
01569 
01570             res = res && OCI_BindUnsignedInt(con->svopt->stmt, MT(":n"), &bufsize);
01571 
01572             if (bufsize == 0)
01573                 res = OCI_BindSetNull(OCI_GetBind(con->svopt->stmt, 1));
01574 
01575             res = res && OCI_Execute(con->svopt->stmt);
01576 
01577             /* prepare the retreival statement call */
01578 
01579             con->svopt->cursize = con->svopt->arrsize;
01580 
01581             res = res && OCI_Prepare(con->svopt->stmt,
01582                                      MT("BEGIN DBMS_OUTPUT.GET_LINES(:s, :i); END;"));
01583 
01584             res = res && OCI_BindArrayOfStrings(con->svopt->stmt,
01585                                                 MT(":s"),
01586                                                 (dtext *) con->svopt->arrbuf,
01587                                                 con->svopt->lnsize,
01588                                                 con->svopt->arrsize);
01589 
01590             res = res && OCI_BindUnsignedInt(con->svopt->stmt,
01591                                              MT(":i"),
01592                                              &con->svopt->cursize);
01593         }
01594     }
01595 
01596     if (res == FALSE)
01597         OCI_ServerDisableOutput(con);
01598 
01599     OCI_RESULT(res);
01600 
01601     return res;
01602 }
01603 
01604 /* --------------------------------------------------------------------------------------------- *
01605  * OCI_ServerDisableOutput
01606  * --------------------------------------------------------------------------------------------- */
01607 
01608 boolean OCI_API OCI_ServerDisableOutput
01609 (
01610     OCI_Connection *con
01611 )
01612 {
01613     boolean res = TRUE;
01614 
01615     OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, FALSE);
01616 
01617     if (con->svopt != NULL)
01618     {
01619         res = res && OCI_ExecuteStmt(con->svopt->stmt,
01620                                      MT("BEGIN DBMS_OUTPUT.DISABLE(); END;"));
01621 
01622         res = res && OCI_StatementFree(con->svopt->stmt);
01623 
01624         OCI_FREE(con->svopt->arrbuf);
01625         OCI_FREE(con->svopt);
01626     }
01627 
01628     OCI_RESULT(res);
01629 
01630     return res;
01631 }
01632 
01633 /* --------------------------------------------------------------------------------------------- *
01634  * OCI_ServerGetOutput
01635  * --------------------------------------------------------------------------------------------- */
01636 
01637 const dtext * OCI_API OCI_ServerGetOutput
01638 (
01639     OCI_Connection *con
01640 )
01641 {
01642     boolean res = TRUE;
01643     dtext *str  = NULL;
01644 
01645     OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, FALSE);
01646     OCI_CHECK(con->svopt == NULL, FALSE);
01647 
01648     if (con->svopt->curpos == 0 || con->svopt->curpos >= con->svopt->cursize)
01649     {
01650         con->svopt->cursize = con->svopt->arrsize;
01651         res                 = OCI_Execute(con->svopt->stmt);
01652         con->svopt->curpos  = 0;
01653     }
01654 
01655     if ((res == TRUE) & (con->svopt->cursize > 0))
01656     {
01657         unsigned int charsize = sizeof(dtext);
01658 
01659         str = (dtext*) (con->svopt->arrbuf +
01660                         (size_t) (((con->svopt->lnsize + 1) * charsize) * con->svopt->curpos++));
01661     }
01662 
01663     OCI_RESULT(res);
01664 
01665     return (const dtext *) str;
01666 }
01667 
01668 /* --------------------------------------------------------------------------------------------- *
01669  * OCI_SetTrace
01670  * --------------------------------------------------------------------------------------------- */
01671 
01672 boolean OCI_API OCI_SetTrace
01673 (
01674     OCI_Connection *con,
01675     unsigned int    trace,
01676     const mtext    *value
01677 )
01678 {
01679     boolean res = TRUE;
01680     mtext *str  = NULL;
01681 
01682     #if OCI_VERSION_COMPILE >= OCI_10_1
01683     ub4 attrib = 0;
01684     #endif
01685 
01686     OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, FALSE);
01687 
01688     /* allocate trace info structure only if trace functions are used */
01689 
01690     if (con->trace == NULL)
01691     {
01692         con->trace = (OCI_TraceInfo *) OCI_MemAlloc(OCI_IPC_TRACE_INFO,
01693                                                     sizeof(*con->trace),
01694                                                     (size_t) 1, TRUE);
01695         res = (con->trace != NULL);
01696     }
01697 
01698     /* set trace properties */
01699 
01700     if (con->trace != NULL)
01701     {
01702         switch (trace)
01703         {
01704         case OCI_TRC_IDENTITY:
01705 
01706             #if OCI_VERSION_COMPILE >= OCI_10_1
01707 
01708             attrib = OCI_ATTR_CLIENT_IDENTIFIER;
01709 
01710             #endif
01711             con->trace->identifier[0] = 0;
01712 
01713             mtsncat(con->trace->identifier, value, OCI_SIZE_TRACE_ID);
01714 
01715             str = con->trace->identifier;
01716 
01717             break;
01718 
01719         case OCI_TRC_MODULE:
01720 
01721             #if OCI_VERSION_COMPILE >= OCI_10_1
01722 
01723             attrib = OCI_ATTR_MODULE;
01724 
01725             #endif
01726             con->trace->module[0] = 0;
01727 
01728             mtsncat(con->trace->module, value, OCI_SIZE_TRACE_MODULE);
01729 
01730             str = con->trace->module;
01731 
01732             break;
01733 
01734         case OCI_TRC_ACTION:
01735 
01736             #if OCI_VERSION_COMPILE >= OCI_10_1
01737 
01738             attrib = OCI_ATTR_ACTION;
01739 
01740             #endif
01741             con->trace->action[0] = 0;
01742 
01743             mtsncat(con->trace->action, value, OCI_SIZE_TRACE_ACTION);
01744 
01745             str = con->trace->action;
01746 
01747             break;
01748 
01749         case OCI_TRC_DETAIL:
01750 
01751             #if OCI_VERSION_COMPILE >= OCI_10_1
01752 
01753             attrib = OCI_ATTR_CLIENT_INFO;
01754 
01755             #endif
01756             con->trace->info[0] = 0;
01757 
01758             mtsncat(con->trace->info, value,  OCI_SIZE_TRACE_INF0);
01759 
01760             str = con->trace->info;
01761 
01762             break;
01763 
01764         default:
01765 
01766             res = FALSE;
01767         }
01768     }
01769 
01770     #if OCI_VERSION_COMPILE >= OCI_10_1
01771 
01772     /* On success, we give the value to Oracle to record it in system session
01773      *view */
01774 
01775     if (res == TRUE)
01776     {
01777         void *ostr = NULL;
01778         int osize  = -1;
01779 
01780         ostr = OCI_GetInputMetaString(str, &osize);
01781 
01782         if (str == NULL)
01783             osize = 0;
01784 
01785         OCI_CALL2
01786         (
01787             res, con,
01788 
01789             OCIAttrSet((dvoid *) con->ses, (ub4) OCI_HTYPE_SESSION,
01790                        (dvoid *) ostr, (ub4) osize, attrib, con->err)
01791         )
01792 
01793         OCI_ReleaseMetaString(ostr);
01794     }
01795 
01796     #endif
01797 
01798     OCI_RESULT(res);
01799 
01800     return res;
01801 }
01802 
01803 /* --------------------------------------------------------------------------------------------- *
01804  * OCI_TraceGet
01805  * --------------------------------------------------------------------------------------------- */
01806 
01807 const mtext * OCI_API OCI_GetTrace
01808 (
01809     OCI_Connection *con,
01810     unsigned int    trace
01811 )
01812 {
01813     const mtext *str = NULL;
01814     boolean res      = TRUE;
01815 
01816     OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, NULL);
01817 
01818     if (con->trace != NULL)
01819     {
01820         switch (trace)
01821         {
01822         case OCI_TRC_IDENTITY:
01823 
01824             str = con->trace->identifier;
01825             break;
01826 
01827         case OCI_TRC_MODULE:
01828 
01829             str = con->trace->module;
01830             break;
01831 
01832         case OCI_TRC_ACTION:
01833 
01834             str = con->trace->action;
01835             break;
01836 
01837         case OCI_TRC_DETAIL:
01838 
01839             str = con->trace->info;
01840             break;
01841 
01842         default:
01843 
01844             res = FALSE;
01845         }
01846     }
01847 
01848     OCI_RESULT(res);
01849 
01850     return str;
01851 }
01852 
01853 /* --------------------------------------------------------------------------------------------- *
01854  * OCI_Ping
01855  * --------------------------------------------------------------------------------------------- */
01856 
01857 boolean OCI_API OCI_Ping
01858 (
01859     OCI_Connection *con
01860 )
01861 {
01862     boolean res = TRUE;
01863     boolean ret = FALSE;
01864 
01865     OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, FALSE);
01866 
01867     #if OCI_VERSION_COMPILE >= OCI_10_2
01868 
01869     if (OCILib.version_runtime >= OCI_10_2)
01870     {
01871         OCI_CALL2
01872         (
01873             res, con,
01874 
01875             OCIPing(con->cxt, con->err, (ub4) OCI_DEFAULT)
01876 
01877         )
01878 
01879         ret = res;
01880     }
01881 
01882     #endif
01883 
01884     OCI_RESULT(res);
01885 
01886     return ret;
01887 }
01888 

Generated on Sun Oct 24 2010 22:02:54 for OCILIB (C Driver for Oracle) by  doxygen 1.7.1