On Mon, Jan 05, 2004 at 07:36:53AM -0500, Eric Lenio wrote:
> Hi Tim, I believe you could use this snippet to determine the current schema if
> DBI is connected to oracle:
> 
>   select sys_context('userenv','current_schema') from dual;
> 
> if you could tell me the preferred way to generate a patch file I will make an
> attempt at it.

Having thought about this some more I think the right fix is for
DBD::Oracle's connect() method to set the Username, USER, and
CURRENT_USER attributes to the result of that query.

So just before the end of the connect sub in Oracle.pm add something
like this:

  unless (length $user_only) {
    $user_only = $dbh->selectrow_array(qq{
        select sys_context('userenv','current_schema') from dual
    });
    $attr->{Username} = $user_only if $attr;
    $dbh->{Username} = $user_only;
    # these are temporary for backwards compatibility
    $dbh->{USER} = $user_only;
    $dbh->{CURRENT_USER} = $user_only;
  }

and then the test script need not be changed.

(There ought to be a more efficient way of asking OCI for the name
but I don't know what it is off-hand.)

Can you try that for me, Eric, and send me a patch?
Thanks.

Tim.

> --Eric.
> 
> On Sun, Jan 04, 2004 at 08:49:14PM +0000, Tim Bunce wrote:
> > The DBI doesn't define a portable way to determine the 'current schema'.
> > Of course there are ways to do it for Oracle but I can't remember it off-hand.
> > A patch to change the test to determine the current schema if $dbh->{USER}
> > is empty would be welcomed.
> > 
> > Tim.
> > 
> > p.s. Yes, $dbh->{USER} isn't part of the DBI spec and shouldn't be relied upon.
> > 
> > On Fri, Jan 02, 2004 at 09:33:11AM -0500, Eric Lenio wrote:
> > > Hi,
> > > 
> > > I have perl 5.8.2, Oracle 8.1.7, and Solaris 9.  I installed DBI 1.39, then was
> > > testing DBD-Oracle 1.14 and it failed the tests in t/select.t which call DBI's
> > > primary_key routine.
> > > 
> > > When I launched 'make test' with DBD-Oracle, I have set the environment var
> > > ORACLE_USERID=/, e.g., I have set up Oracle OS authentication (with the
> > > os_authen_prefix oracle init parameter) to connect to oracle so no
> > > username/password are necessary.
> > > 
> > > So the DBI primary_key expects a schema as the 2nd arg to it, in my case this
> > > is a blank, and thus I think this is why the tests fail.  t/select.t has this:
> > > 
> > >   my @pk = $dbh->primary_key(undef, $dbh->{USER}, uc $table);
> > > 
> > > Upon reading the DBI docs I cannot seem to find more info on $dbh->{USER}.
> > > If I manually set the 2nd arg to the true oracle user then the tests pass.
> > > Is there a better way to do this?  Should I not be using ORACLE_USERID?
> > > 
> > > Thanks,
> > > Eric.
> > 

Reply via email to