Grokbase Groups Perl dbi-dev May 2003
FAQ

Tim Bunce writes:
On Tue, May 13, 2003 at 09:39:02AM +0200, Kristian Nielsen wrote:
I was wondering if there is any interest in having support in
DBD::Oracle for sharing database connections with ProC/SQLLIB code?
Yes, thanks!

Please send me a patch over the next release of DBD::Oracle.
Appended is a patch for the 'ora_use_proc_connection' against
DBD::Oracle version 1.14. I have merged the logic into the existing
dbd_db_login6() code, and have added some documentation in Oracle.pm.

I have tried to make it compatible with the new ithread/ora_dbh_share
stuff, but I have not tested it (as stated in the documentation).

In case the code adds some new dependencies on installed Oracle client
software I will try to add some conditional logic to the Makefile, but
it compiles cleanly for us.

Comments/suggestions are welcome.

- Kristian.

--
Kristian Nielsen kn@sifira.dk
Development Manager, Sifira A/S

-----------------------------------------------------------------------
diff -u --recursive DBD-Oracle.orig/Makefile.PL DBD-Oracle.new/Makefile.PL
--- DBD-Oracle.orig/Makefile.PL Wed May 14 12:38:15 2003
+++ DBD-Oracle.new/Makefile.PL Wed May 14 12:53:04 2003
@@ -275,7 +275,7 @@
$opts{LIBS} = [ "-L$OH/$OCIDIR/LIB/$oci_compiler_dir $OCILIB" ];
};

- my $OCIINCLUDE = "-I$OH/$OCIDIR/include -I$OH/rdbms/demo";
+ my $OCIINCLUDE = "-I$OH/$OCIDIR/include -I$OH/rdbms/demo -I$OH/precomp/public";
$opts{INC} = "$OCIINCLUDE -I$dbi_arch_dir";
}

@@ -557,7 +557,7 @@
}

my $OCIINCLUDE = expand_mkvars($MK{INCLUDE} || '', 0, 0);
- $OCIINCLUDE .= " -I$OH/rdbms/demo";
+ $OCIINCLUDE .= " -I$OH/rdbms/demo -I$OH/precomp/public";
my $inc = join " ", map { "-I$OH/$_" } @h_dirs;
$opts{INC} = "$OCIINCLUDE $inc -I$dbi_arch_dir";
}
diff -u --recursive DBD-Oracle.orig/Oracle.pm DBD-Oracle.new/Oracle.pm
--- DBD-Oracle.orig/Oracle.pm Wed May 14 12:38:15 2003
+++ DBD-Oracle.new/Oracle.pm Wed May 14 12:53:04 2003
@@ -1105,6 +1105,28 @@

$dbh = DBI -> connect ($dsn, $user, $passwd, {ora_dbh_share => \$orashr}) ;

+=item ora_use_proc_connection
+
+This attribute allows to create a DBI handle for an existing SQLLIB
+database connection. This can be used to share database connections
+between Oracle ProC code and DBI running in an embedded Perl interpreter.
+The SQLLIB connection id is appended after the "dbi:Oracle:" initial
+argument to DBI::connect.
+
+For example, if in ProC a connection is made like
+
+ EXEC SQL CONNECT 'user/pass@db' AT 'CONID';
+
+the connection may be used from DBI after running something like
+
+ my $dbh = DBI->connect("dbi:Oracle:CONID", "", "",
+ { ora_use_proc_connection => 1 });
+
+To disconnect, first call $dbh->disconnect(), then disconnect in ProC.
+
+This attribute is not available with OCI_V7. Not tested with Perl
+ithreads or with the ora_dbh_share connect attribute.
+
=back

=head2 Database Handle Attributes
diff -u --recursive DBD-Oracle.orig/dbdimp.c DBD-Oracle.new/dbdimp.c
--- DBD-Oracle.orig/dbdimp.c Wed May 14 12:38:15 2003
+++ DBD-Oracle.new/dbdimp.c Wed May 14 12:53:04 2003
@@ -15,6 +15,7 @@
#endif

#include "Oracle.h"
+#include <sql2oci.h>


/* XXX DBI should provide a better version of this */
@@ -227,6 +228,8 @@
#endif
#ifdef OCI_V8_SYNTAX
struct OCIExtProcContext *this_ctx;
+ ub4 use_proc_connection = 0;
+ SV **use_proc_connection_sv;
#endif
D_imp_drh_from_dbh;

@@ -273,6 +276,11 @@
}
}
#endif
+
+ /* Check if we should re-use a ProC connection and not connect ourselves. */
+ DBD_ATTRIB_GET_IV(attr, "ora_use_proc_connection", 23,
+ use_proc_connection_sv, use_proc_connection);
+
#ifdef OCI_V8_SYNTAX

imp_dbh->get_oci_handle = oci_db_handle;
@@ -310,27 +318,53 @@
#if defined(USE_ITHREADS) || defined(MULTIPLICITY) || defined(USE_5005THREADS)
init_mode |= OCI_THREADED;
#endif
- /* XXX recent oracle docs recommend using OCIEnvCreate() instead of */
- /* OCIInitialize + OCIEnvInit, we'd need ifdef's for old versions */
- OCIInitialize_log_stat(init_mode, 0, 0,0,0, status);
- if (status != OCI_SUCCESS) {
- oci_error(dbh, NULL, status,
- "OCIInitialize. Check ORACLE_HOME and NLS settings etc.");
- return 0;
+ if(use_proc_connection) {
+ /* Use existing SQLLIB connection. Do not call OCIInitialize(), */
+ /* since presumably SQLLIB already did that. */
+ status = SQLEnvGet(SQL_SINGLE_RCTX, &imp_drh->envhp);
+ imp_drh->proc_handles = 1;
+ if (status != SQL_SUCCESS) {
+ oci_error(dbh, NULL, status,
+ "SQLEnvGet. Failed to load ProC environment.");
+ return 0;
+ }
}
- OCIEnvInit_log_stat( &imp_drh->envhp, OCI_DEFAULT, 0, 0, status);
- if (status != OCI_SUCCESS) {
- oci_error(dbh, (OCIError*)imp_dbh->envhp, status, "OCIEnvInit");
- return 0;
+ else { /* Normal connect. */
+ imp_drh->proc_handles = 0;
+ /* XXX recent oracle docs recommend using OCIEnvCreate() instead of */
+ /* OCIInitialize + OCIEnvInit, we'd need ifdef's for old versions */
+ OCIInitialize_log_stat(init_mode, 0, 0,0,0, status);
+ if (status != OCI_SUCCESS) {
+ oci_error(dbh, NULL, status,
+ "OCIInitialize. Check ORACLE_HOME and NLS settings etc.");
+ return 0;
+ }
+ OCIEnvInit_log_stat( &imp_drh->envhp, OCI_DEFAULT, 0, 0, status);
+ if (status != OCI_SUCCESS) {
+ oci_error(dbh, (OCIError*)imp_dbh->envhp, status, "OCIEnvInit");
+ return 0;
+ }
}
}

if (shared_dbh_ssv) {
if (!imp_dbh->envhp) {
- OCIEnvInit_log_stat( &imp_dbh->envhp, OCI_DEFAULT, 0, 0, status);
- if (status != OCI_SUCCESS) {
- oci_error(dbh, (OCIError*)imp_dbh->envhp, status, "OCIEnvInit");
- return 0;
+ if(use_proc_connection) {
+ status = SQLEnvGet(SQL_SINGLE_RCTX, &imp_dbh->envhp);
+ imp_dbh->proc_handles = 1;
+ if (status != SQL_SUCCESS) {
+ oci_error(dbh, (OCIError*)imp_dbh->envhp, status,
+ "SQLEnvGet. Failed to load ProC environment.");
+ return 0;
+ }
+ }
+ else {
+ OCIEnvInit_log_stat( &imp_dbh->envhp, OCI_DEFAULT, 0, 0, status);
+ imp_dbh->proc_handles = 0;
+ if (status != OCI_SUCCESS) {
+ oci_error(dbh, (OCIError*)imp_dbh->envhp, status, "OCIEnvInit");
+ return 0;
+ }
}
}
}
@@ -341,54 +375,88 @@
OCIHandleAlloc_ok(imp_dbh->envhp, &imp_dbh->errhp, OCI_HTYPE_ERROR, status);

if (!shared_dbh) {
- OCIHandleAlloc_ok(imp_dbh->envhp, &imp_dbh->srvhp, OCI_HTYPE_SERVER, status);
- OCIHandleAlloc_ok(imp_dbh->envhp, &imp_dbh->svchp, OCI_HTYPE_SVCCTX, status);
+ if(use_proc_connection) {
+ imp_dbh->proc_handles = 1;
+ status = SQLSvcCtxGet(SQL_SINGLE_RCTX, dbname, strlen(dbname),
+ &imp_dbh->svchp);
+ if (status != SQL_SUCCESS) {
+ oci_error(dbh, imp_dbh->errhp, status, "SQLSvcCtxGet");
+ OCIHandleFree_log_stat(imp_dbh->errhp, OCI_HTYPE_ERROR, status);
+ return 0;
+ }

- OCIServerAttach_log_stat(imp_dbh, dbname, status);
- if (status != OCI_SUCCESS) {
- oci_error(dbh, imp_dbh->errhp, status, "OCIServerAttach");
- OCIHandleFree_log_stat(imp_dbh->srvhp, OCI_HTYPE_SERVER, status);
- OCIHandleFree_log_stat(imp_dbh->svchp, OCI_HTYPE_SVCCTX, status);
- OCIHandleFree_log_stat(imp_dbh->errhp, OCI_HTYPE_ERROR, status);
- return 0;
+ OCIAttrGet_log_stat(imp_dbh->svchp, OCI_HTYPE_SVCCTX, &imp_dbh->srvhp, NULL,
+ OCI_ATTR_SERVER, imp_dbh->errhp, status);
+ if (status != OCI_SUCCESS) {
+ oci_error(dbh, imp_dbh->errhp, status,
+ "OCIAttrGet. Failed to get server context.");
+ OCIHandleFree_log_stat(imp_dbh->errhp, OCI_HTYPE_ERROR, status);
+ return 0;
+ }
+
+ OCIAttrGet_log_stat(imp_dbh->svchp, OCI_HTYPE_SVCCTX, &imp_dbh->authp, NULL,
+ OCI_ATTR_SESSION, imp_dbh->errhp, status);
+ if (status != OCI_SUCCESS) {
+ oci_error(dbh, imp_dbh->errhp, status,
+ "OCIAttrGet. Failed to get authentication context.");
+ OCIHandleFree_log_stat(imp_dbh->errhp, OCI_HTYPE_ERROR, status);
+ return 0;
+ }
}
+ else { /* !use_proc_connection */
+ imp_dbh->proc_handles = 0;
+ OCIHandleAlloc_ok(imp_dbh->envhp, &imp_dbh->srvhp, OCI_HTYPE_SERVER, status);
+ OCIHandleAlloc_ok(imp_dbh->envhp, &imp_dbh->svchp, OCI_HTYPE_SVCCTX, status);

- OCIAttrSet_log_stat( imp_dbh->svchp, OCI_HTYPE_SVCCTX, imp_dbh->srvhp,
- (ub4) 0, OCI_ATTR_SERVER, imp_dbh->errhp, status);
+ OCIServerAttach_log_stat(imp_dbh, dbname, status);
+ if (status != OCI_SUCCESS) {
+ oci_error(dbh, imp_dbh->errhp, status, "OCIServerAttach");
+ OCIHandleFree_log_stat(imp_dbh->srvhp, OCI_HTYPE_SERVER, status);
+ OCIHandleFree_log_stat(imp_dbh->svchp, OCI_HTYPE_SVCCTX, status);
+ OCIHandleFree_log_stat(imp_dbh->errhp, OCI_HTYPE_ERROR, status);
+ return 0;
+ }

- OCIHandleAlloc_ok(imp_dbh->envhp, &imp_dbh->authp, OCI_HTYPE_SESSION, status);
+ OCIAttrSet_log_stat( imp_dbh->svchp, OCI_HTYPE_SVCCTX, imp_dbh->srvhp,
+ (ub4) 0, OCI_ATTR_SERVER, imp_dbh->errhp, status);

- {
- ub4 cred_type = ora_parse_uid(imp_dbh, &uid, &pwd);
- SV **sess_mode_type_sv;
- ub4 sess_mode_type = OCI_DEFAULT;
- DBD_ATTRIB_GET_IV(attr, "ora_session_mode",16, sess_mode_type_sv, sess_mode_type);
- OCISessionBegin_log_stat( imp_dbh->svchp, imp_dbh->errhp, imp_dbh->authp,
- cred_type, sess_mode_type, status);
- }
- if (status == OCI_SUCCESS_WITH_INFO) {
- /* eg ORA-28011: the account will expire soon; change your password now */
- /* XXX trigger HandleEvent here in future */
- status = OCI_SUCCESS;
- }
- if (status != OCI_SUCCESS) {
- oci_error(dbh, imp_dbh->errhp, status, "OCISessionBegin");
- OCIServerDetach_log_stat(imp_dbh->srvhp, imp_dbh->errhp, OCI_DEFAULT, status);
- OCIHandleFree_log_stat(imp_dbh->authp, OCI_HTYPE_SESSION,status);
- OCIHandleFree_log_stat(imp_dbh->srvhp, OCI_HTYPE_SERVER, status);
- OCIHandleFree_log_stat(imp_dbh->errhp, OCI_HTYPE_ERROR, status);
- OCIHandleFree_log_stat(imp_dbh->svchp, OCI_HTYPE_SVCCTX, status);
- return 0;
- }
-
- OCIAttrSet_log_stat(imp_dbh->svchp, (ub4) OCI_HTYPE_SVCCTX,
- imp_dbh->authp, (ub4) 0,
- (ub4) OCI_ATTR_SESSION, imp_dbh->errhp, status);
+ OCIHandleAlloc_ok(imp_dbh->envhp, &imp_dbh->authp, OCI_HTYPE_SESSION, status);
+
+ {
+ ub4 cred_type = ora_parse_uid(imp_dbh, &uid, &pwd);
+ SV **sess_mode_type_sv;
+ ub4 sess_mode_type = OCI_DEFAULT;
+ DBD_ATTRIB_GET_IV(attr, "ora_session_mode",16, sess_mode_type_sv, sess_mode_type);
+ OCISessionBegin_log_stat( imp_dbh->svchp, imp_dbh->errhp, imp_dbh->authp,
+ cred_type, sess_mode_type, status);
+ }
+ if (status == OCI_SUCCESS_WITH_INFO) {
+ /* eg ORA-28011: the account will expire soon; change your password now */
+ /* XXX trigger HandleEvent here in future */
+ status = OCI_SUCCESS;
+ }
+ if (status != OCI_SUCCESS) {
+ oci_error(dbh, imp_dbh->errhp, status, "OCISessionBegin");
+ OCIServerDetach_log_stat(imp_dbh->srvhp, imp_dbh->errhp, OCI_DEFAULT, status);
+ OCIHandleFree_log_stat(imp_dbh->authp, OCI_HTYPE_SESSION,status);
+ OCIHandleFree_log_stat(imp_dbh->srvhp, OCI_HTYPE_SERVER, status);
+ OCIHandleFree_log_stat(imp_dbh->errhp, OCI_HTYPE_ERROR, status);
+ OCIHandleFree_log_stat(imp_dbh->svchp, OCI_HTYPE_SVCCTX, status);
+ return 0;
+ }
+
+ OCIAttrSet_log_stat(imp_dbh->svchp, (ub4) OCI_HTYPE_SVCCTX,
+ imp_dbh->authp, (ub4) 0,
+ (ub4) OCI_ATTR_SESSION, imp_dbh->errhp, status);
+ } /* use_proc_connection */
}
#else
if (DBIS->debug >= 6 )
dump_env_to_trace();

+ if(use_proc_connection)
+ croak("ora_use_proc_connection attribute not available with OCI_V7.");
+
imp_dbh->lda = &imp_dbh->ldabuf;
imp_dbh->hda = &imp_dbh->hdabuf[0];
/* can give duplicate free errors (from Oracle) if connect fails */
@@ -571,7 +639,7 @@
/* See DBI Driver.xst file for the DBI approach. */

#ifdef OCI_V8_SYNTAX
- if (refcnt == 1) {
+ if (refcnt == 1 && !imp_dbh->proc_handles) {
sword s_se, s_sd;
OCISessionEnd_log_stat(imp_dbh->svchp, imp_dbh->errhp, imp_dbh->authp,
OCI_DEFAULT, s_se);
@@ -613,6 +681,7 @@
if (DBIc_ACTIVE(imp_dbh))
dbd_db_disconnect(dbh, imp_dbh);
#ifdef OCI_V8_SYNTAX
+ if (!imp_dbh->proc_handles)
{ sword status;
OCIHandleFree_log_stat(imp_dbh->authp, OCI_HTYPE_SESSION,status);
OCIHandleFree_log_stat(imp_dbh->srvhp, OCI_HTYPE_SERVER, status);
diff -u --recursive DBD-Oracle.orig/dbdimp.h DBD-Oracle.new/dbdimp.h
--- DBD-Oracle.orig/dbdimp.h Wed May 14 12:38:15 2003
+++ DBD-Oracle.new/dbdimp.h Wed May 14 12:53:04 2003
@@ -78,6 +78,8 @@
dbih_drc_t com; /* MUST be first element in structure */
#ifdef OCI_V8_SYNTAX
OCIEnv *envhp;
+ int proc_handles; /* If true, the envhp handle is owned by ProC
+ and must not be freed. */
#endif
SV *ora_long;
SV *ora_trunc;
@@ -103,6 +105,8 @@
OCIServer *srvhp;
OCISvcCtx *svchp;
OCISession *authp;
+ int proc_handles; /* If true, srvhp, svchp, and authp handles
+ are owned by ProC and must not be freed. */
#else
Lda_Def ldabuf;
Lda_Def *lda; /* points to ldabuf */

Search Discussions

  • Tim Bunce at May 14, 2003 at 1:42 pm
    Thanks!

    Tim.
    On Wed, May 14, 2003 at 02:08:43PM +0200, Kristian Nielsen wrote:
    Tim Bunce <Tim.Bunce@pobox.com> writes:
    On Tue, May 13, 2003 at 09:39:02AM +0200, Kristian Nielsen wrote:
    I was wondering if there is any interest in having support in
    DBD::Oracle for sharing database connections with ProC/SQLLIB code?
    Yes, thanks!

    Please send me a patch over the next release of DBD::Oracle.
    Appended is a patch for the 'ora_use_proc_connection' against
    DBD::Oracle version 1.14. I have merged the logic into the existing
    dbd_db_login6() code, and have added some documentation in Oracle.pm.

    I have tried to make it compatible with the new ithread/ora_dbh_share
    stuff, but I have not tested it (as stated in the documentation).

    In case the code adds some new dependencies on installed Oracle client
    software I will try to add some conditional logic to the Makefile, but
    it compiles cleanly for us.

    Comments/suggestions are welcome.

    - Kristian.

    --
    Kristian Nielsen kn@sifira.dk
    Development Manager, Sifira A/S

    -----------------------------------------------------------------------
    diff -u --recursive DBD-Oracle.orig/Makefile.PL DBD-Oracle.new/Makefile.PL
    --- DBD-Oracle.orig/Makefile.PL Wed May 14 12:38:15 2003
    +++ DBD-Oracle.new/Makefile.PL Wed May 14 12:53:04 2003
    @@ -275,7 +275,7 @@
    $opts{LIBS} = [ "-L$OH/$OCIDIR/LIB/$oci_compiler_dir $OCILIB" ];
    };

    - my $OCIINCLUDE = "-I$OH/$OCIDIR/include -I$OH/rdbms/demo";
    + my $OCIINCLUDE = "-I$OH/$OCIDIR/include -I$OH/rdbms/demo -I$OH/precomp/public";
    $opts{INC} = "$OCIINCLUDE -I$dbi_arch_dir";
    }

    @@ -557,7 +557,7 @@
    }

    my $OCIINCLUDE = expand_mkvars($MK{INCLUDE} || '', 0, 0);
    - $OCIINCLUDE .= " -I$OH/rdbms/demo";
    + $OCIINCLUDE .= " -I$OH/rdbms/demo -I$OH/precomp/public";
    my $inc = join " ", map { "-I$OH/$_" } @h_dirs;
    $opts{INC} = "$OCIINCLUDE $inc -I$dbi_arch_dir";
    }
    diff -u --recursive DBD-Oracle.orig/Oracle.pm DBD-Oracle.new/Oracle.pm
    --- DBD-Oracle.orig/Oracle.pm Wed May 14 12:38:15 2003
    +++ DBD-Oracle.new/Oracle.pm Wed May 14 12:53:04 2003
    @@ -1105,6 +1105,28 @@

    $dbh = DBI -> connect ($dsn, $user, $passwd, {ora_dbh_share => \$orashr}) ;

    +=item ora_use_proc_connection
    +
    +This attribute allows to create a DBI handle for an existing SQLLIB
    +database connection. This can be used to share database connections
    +between Oracle ProC code and DBI running in an embedded Perl interpreter.
    +The SQLLIB connection id is appended after the "dbi:Oracle:" initial
    +argument to DBI::connect.
    +
    +For example, if in ProC a connection is made like
    +
    + EXEC SQL CONNECT 'user/pass@db' AT 'CONID';
    +
    +the connection may be used from DBI after running something like
    +
    + my $dbh = DBI->connect("dbi:Oracle:CONID", "", "",
    + { ora_use_proc_connection => 1 });
    +
    +To disconnect, first call $dbh->disconnect(), then disconnect in ProC.
    +
    +This attribute is not available with OCI_V7. Not tested with Perl
    +ithreads or with the ora_dbh_share connect attribute.
    +
    =back

    =head2 Database Handle Attributes
    diff -u --recursive DBD-Oracle.orig/dbdimp.c DBD-Oracle.new/dbdimp.c
    --- DBD-Oracle.orig/dbdimp.c Wed May 14 12:38:15 2003
    +++ DBD-Oracle.new/dbdimp.c Wed May 14 12:53:04 2003
    @@ -15,6 +15,7 @@
    #endif

    #include "Oracle.h"
    +#include <sql2oci.h>


    /* XXX DBI should provide a better version of this */
    @@ -227,6 +228,8 @@
    #endif
    #ifdef OCI_V8_SYNTAX
    struct OCIExtProcContext *this_ctx;
    + ub4 use_proc_connection = 0;
    + SV **use_proc_connection_sv;
    #endif
    D_imp_drh_from_dbh;

    @@ -273,6 +276,11 @@
    }
    }
    #endif
    +
    + /* Check if we should re-use a ProC connection and not connect ourselves. */
    + DBD_ATTRIB_GET_IV(attr, "ora_use_proc_connection", 23,
    + use_proc_connection_sv, use_proc_connection);
    +
    #ifdef OCI_V8_SYNTAX

    imp_dbh->get_oci_handle = oci_db_handle;
    @@ -310,27 +318,53 @@
    #if defined(USE_ITHREADS) || defined(MULTIPLICITY) || defined(USE_5005THREADS)
    init_mode |= OCI_THREADED;
    #endif
    - /* XXX recent oracle docs recommend using OCIEnvCreate() instead of */
    - /* OCIInitialize + OCIEnvInit, we'd need ifdef's for old versions */
    - OCIInitialize_log_stat(init_mode, 0, 0,0,0, status);
    - if (status != OCI_SUCCESS) {
    - oci_error(dbh, NULL, status,
    - "OCIInitialize. Check ORACLE_HOME and NLS settings etc.");
    - return 0;
    + if(use_proc_connection) {
    + /* Use existing SQLLIB connection. Do not call OCIInitialize(), */
    + /* since presumably SQLLIB already did that. */
    + status = SQLEnvGet(SQL_SINGLE_RCTX, &imp_drh->envhp);
    + imp_drh->proc_handles = 1;
    + if (status != SQL_SUCCESS) {
    + oci_error(dbh, NULL, status,
    + "SQLEnvGet. Failed to load ProC environment.");
    + return 0;
    + }
    }
    - OCIEnvInit_log_stat( &imp_drh->envhp, OCI_DEFAULT, 0, 0, status);
    - if (status != OCI_SUCCESS) {
    - oci_error(dbh, (OCIError*)imp_dbh->envhp, status, "OCIEnvInit");
    - return 0;
    + else { /* Normal connect. */
    + imp_drh->proc_handles = 0;
    + /* XXX recent oracle docs recommend using OCIEnvCreate() instead of */
    + /* OCIInitialize + OCIEnvInit, we'd need ifdef's for old versions */
    + OCIInitialize_log_stat(init_mode, 0, 0,0,0, status);
    + if (status != OCI_SUCCESS) {
    + oci_error(dbh, NULL, status,
    + "OCIInitialize. Check ORACLE_HOME and NLS settings etc.");
    + return 0;
    + }
    + OCIEnvInit_log_stat( &imp_drh->envhp, OCI_DEFAULT, 0, 0, status);
    + if (status != OCI_SUCCESS) {
    + oci_error(dbh, (OCIError*)imp_dbh->envhp, status, "OCIEnvInit");
    + return 0;
    + }
    }
    }

    if (shared_dbh_ssv) {
    if (!imp_dbh->envhp) {
    - OCIEnvInit_log_stat( &imp_dbh->envhp, OCI_DEFAULT, 0, 0, status);
    - if (status != OCI_SUCCESS) {
    - oci_error(dbh, (OCIError*)imp_dbh->envhp, status, "OCIEnvInit");
    - return 0;
    + if(use_proc_connection) {
    + status = SQLEnvGet(SQL_SINGLE_RCTX, &imp_dbh->envhp);
    + imp_dbh->proc_handles = 1;
    + if (status != SQL_SUCCESS) {
    + oci_error(dbh, (OCIError*)imp_dbh->envhp, status,
    + "SQLEnvGet. Failed to load ProC environment.");
    + return 0;
    + }
    + }
    + else {
    + OCIEnvInit_log_stat( &imp_dbh->envhp, OCI_DEFAULT, 0, 0, status);
    + imp_dbh->proc_handles = 0;
    + if (status != OCI_SUCCESS) {
    + oci_error(dbh, (OCIError*)imp_dbh->envhp, status, "OCIEnvInit");
    + return 0;
    + }
    }
    }
    }
    @@ -341,54 +375,88 @@
    OCIHandleAlloc_ok(imp_dbh->envhp, &imp_dbh->errhp, OCI_HTYPE_ERROR, status);

    if (!shared_dbh) {
    - OCIHandleAlloc_ok(imp_dbh->envhp, &imp_dbh->srvhp, OCI_HTYPE_SERVER, status);
    - OCIHandleAlloc_ok(imp_dbh->envhp, &imp_dbh->svchp, OCI_HTYPE_SVCCTX, status);
    + if(use_proc_connection) {
    + imp_dbh->proc_handles = 1;
    + status = SQLSvcCtxGet(SQL_SINGLE_RCTX, dbname, strlen(dbname),
    + &imp_dbh->svchp);
    + if (status != SQL_SUCCESS) {
    + oci_error(dbh, imp_dbh->errhp, status, "SQLSvcCtxGet");
    + OCIHandleFree_log_stat(imp_dbh->errhp, OCI_HTYPE_ERROR, status);
    + return 0;
    + }

    - OCIServerAttach_log_stat(imp_dbh, dbname, status);
    - if (status != OCI_SUCCESS) {
    - oci_error(dbh, imp_dbh->errhp, status, "OCIServerAttach");
    - OCIHandleFree_log_stat(imp_dbh->srvhp, OCI_HTYPE_SERVER, status);
    - OCIHandleFree_log_stat(imp_dbh->svchp, OCI_HTYPE_SVCCTX, status);
    - OCIHandleFree_log_stat(imp_dbh->errhp, OCI_HTYPE_ERROR, status);
    - return 0;
    + OCIAttrGet_log_stat(imp_dbh->svchp, OCI_HTYPE_SVCCTX, &imp_dbh->srvhp, NULL,
    + OCI_ATTR_SERVER, imp_dbh->errhp, status);
    + if (status != OCI_SUCCESS) {
    + oci_error(dbh, imp_dbh->errhp, status,
    + "OCIAttrGet. Failed to get server context.");
    + OCIHandleFree_log_stat(imp_dbh->errhp, OCI_HTYPE_ERROR, status);
    + return 0;
    + }
    +
    + OCIAttrGet_log_stat(imp_dbh->svchp, OCI_HTYPE_SVCCTX, &imp_dbh->authp, NULL,
    + OCI_ATTR_SESSION, imp_dbh->errhp, status);
    + if (status != OCI_SUCCESS) {
    + oci_error(dbh, imp_dbh->errhp, status,
    + "OCIAttrGet. Failed to get authentication context.");
    + OCIHandleFree_log_stat(imp_dbh->errhp, OCI_HTYPE_ERROR, status);
    + return 0;
    + }
    }
    + else { /* !use_proc_connection */
    + imp_dbh->proc_handles = 0;
    + OCIHandleAlloc_ok(imp_dbh->envhp, &imp_dbh->srvhp, OCI_HTYPE_SERVER, status);
    + OCIHandleAlloc_ok(imp_dbh->envhp, &imp_dbh->svchp, OCI_HTYPE_SVCCTX, status);

    - OCIAttrSet_log_stat( imp_dbh->svchp, OCI_HTYPE_SVCCTX, imp_dbh->srvhp,
    - (ub4) 0, OCI_ATTR_SERVER, imp_dbh->errhp, status);
    + OCIServerAttach_log_stat(imp_dbh, dbname, status);
    + if (status != OCI_SUCCESS) {
    + oci_error(dbh, imp_dbh->errhp, status, "OCIServerAttach");
    + OCIHandleFree_log_stat(imp_dbh->srvhp, OCI_HTYPE_SERVER, status);
    + OCIHandleFree_log_stat(imp_dbh->svchp, OCI_HTYPE_SVCCTX, status);
    + OCIHandleFree_log_stat(imp_dbh->errhp, OCI_HTYPE_ERROR, status);
    + return 0;
    + }

    - OCIHandleAlloc_ok(imp_dbh->envhp, &imp_dbh->authp, OCI_HTYPE_SESSION, status);
    + OCIAttrSet_log_stat( imp_dbh->svchp, OCI_HTYPE_SVCCTX, imp_dbh->srvhp,
    + (ub4) 0, OCI_ATTR_SERVER, imp_dbh->errhp, status);

    - {
    - ub4 cred_type = ora_parse_uid(imp_dbh, &uid, &pwd);
    - SV **sess_mode_type_sv;
    - ub4 sess_mode_type = OCI_DEFAULT;
    - DBD_ATTRIB_GET_IV(attr, "ora_session_mode",16, sess_mode_type_sv, sess_mode_type);
    - OCISessionBegin_log_stat( imp_dbh->svchp, imp_dbh->errhp, imp_dbh->authp,
    - cred_type, sess_mode_type, status);
    - }
    - if (status == OCI_SUCCESS_WITH_INFO) {
    - /* eg ORA-28011: the account will expire soon; change your password now */
    - /* XXX trigger HandleEvent here in future */
    - status = OCI_SUCCESS;
    - }
    - if (status != OCI_SUCCESS) {
    - oci_error(dbh, imp_dbh->errhp, status, "OCISessionBegin");
    - OCIServerDetach_log_stat(imp_dbh->srvhp, imp_dbh->errhp, OCI_DEFAULT, status);
    - OCIHandleFree_log_stat(imp_dbh->authp, OCI_HTYPE_SESSION,status);
    - OCIHandleFree_log_stat(imp_dbh->srvhp, OCI_HTYPE_SERVER, status);
    - OCIHandleFree_log_stat(imp_dbh->errhp, OCI_HTYPE_ERROR, status);
    - OCIHandleFree_log_stat(imp_dbh->svchp, OCI_HTYPE_SVCCTX, status);
    - return 0;
    - }
    -
    - OCIAttrSet_log_stat(imp_dbh->svchp, (ub4) OCI_HTYPE_SVCCTX,
    - imp_dbh->authp, (ub4) 0,
    - (ub4) OCI_ATTR_SESSION, imp_dbh->errhp, status);
    + OCIHandleAlloc_ok(imp_dbh->envhp, &imp_dbh->authp, OCI_HTYPE_SESSION, status);
    +
    + {
    + ub4 cred_type = ora_parse_uid(imp_dbh, &uid, &pwd);
    + SV **sess_mode_type_sv;
    + ub4 sess_mode_type = OCI_DEFAULT;
    + DBD_ATTRIB_GET_IV(attr, "ora_session_mode",16, sess_mode_type_sv, sess_mode_type);
    + OCISessionBegin_log_stat( imp_dbh->svchp, imp_dbh->errhp, imp_dbh->authp,
    + cred_type, sess_mode_type, status);
    + }
    + if (status == OCI_SUCCESS_WITH_INFO) {
    + /* eg ORA-28011: the account will expire soon; change your password now */
    + /* XXX trigger HandleEvent here in future */
    + status = OCI_SUCCESS;
    + }
    + if (status != OCI_SUCCESS) {
    + oci_error(dbh, imp_dbh->errhp, status, "OCISessionBegin");
    + OCIServerDetach_log_stat(imp_dbh->srvhp, imp_dbh->errhp, OCI_DEFAULT, status);
    + OCIHandleFree_log_stat(imp_dbh->authp, OCI_HTYPE_SESSION,status);
    + OCIHandleFree_log_stat(imp_dbh->srvhp, OCI_HTYPE_SERVER, status);
    + OCIHandleFree_log_stat(imp_dbh->errhp, OCI_HTYPE_ERROR, status);
    + OCIHandleFree_log_stat(imp_dbh->svchp, OCI_HTYPE_SVCCTX, status);
    + return 0;
    + }
    +
    + OCIAttrSet_log_stat(imp_dbh->svchp, (ub4) OCI_HTYPE_SVCCTX,
    + imp_dbh->authp, (ub4) 0,
    + (ub4) OCI_ATTR_SESSION, imp_dbh->errhp, status);
    + } /* use_proc_connection */
    }
    #else
    if (DBIS->debug >= 6 )
    dump_env_to_trace();

    + if(use_proc_connection)
    + croak("ora_use_proc_connection attribute not available with OCI_V7.");
    +
    imp_dbh->lda = &imp_dbh->ldabuf;
    imp_dbh->hda = &imp_dbh->hdabuf[0];
    /* can give duplicate free errors (from Oracle) if connect fails */
    @@ -571,7 +639,7 @@
    /* See DBI Driver.xst file for the DBI approach. */

    #ifdef OCI_V8_SYNTAX
    - if (refcnt == 1) {
    + if (refcnt == 1 && !imp_dbh->proc_handles) {
    sword s_se, s_sd;
    OCISessionEnd_log_stat(imp_dbh->svchp, imp_dbh->errhp, imp_dbh->authp,
    OCI_DEFAULT, s_se);
    @@ -613,6 +681,7 @@
    if (DBIc_ACTIVE(imp_dbh))
    dbd_db_disconnect(dbh, imp_dbh);
    #ifdef OCI_V8_SYNTAX
    + if (!imp_dbh->proc_handles)
    { sword status;
    OCIHandleFree_log_stat(imp_dbh->authp, OCI_HTYPE_SESSION,status);
    OCIHandleFree_log_stat(imp_dbh->srvhp, OCI_HTYPE_SERVER, status);
    diff -u --recursive DBD-Oracle.orig/dbdimp.h DBD-Oracle.new/dbdimp.h
    --- DBD-Oracle.orig/dbdimp.h Wed May 14 12:38:15 2003
    +++ DBD-Oracle.new/dbdimp.h Wed May 14 12:53:04 2003
    @@ -78,6 +78,8 @@
    dbih_drc_t com; /* MUST be first element in structure */
    #ifdef OCI_V8_SYNTAX
    OCIEnv *envhp;
    + int proc_handles; /* If true, the envhp handle is owned by ProC
    + and must not be freed. */
    #endif
    SV *ora_long;
    SV *ora_trunc;
    @@ -103,6 +105,8 @@
    OCIServer *srvhp;
    OCISvcCtx *svchp;
    OCISession *authp;
    + int proc_handles; /* If true, srvhp, svchp, and authp handles
    + are owned by ProC and must not be freed. */
    #else
    Lda_Def ldabuf;
    Lda_Def *lda; /* points to ldabuf */

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupdbi-dev @
categoriesperl
postedMay 14, '03 at 12:09p
activeMay 14, '03 at 1:42p
posts2
users2
websitedbi.perl.org

2 users in discussion

Tim Bunce: 1 post Kristian Nielsen: 1 post

People

Translate

site design / logo © 2019 Grokbase