dbaad has asked for the wisdom of the Perl Monks concerning the following question:

Hello,

When I run a script from shell using DBI and I have LIBPATH set to something other than when DBI was compiled, I get a install_driver(oracle) error and the script dies.

$dbh = DBI->connect(dbi:Oracle:etc.....)

unsetting LIBPATH always works. The problem is I want to trap this error so the script doesn't die if someone executes it with the wrong LIBPATH. The only way I have found to do this is the expensive operation of calling

my @drivers = DBI->installed_versions;

and then check to see if Oracle is there before I DBI->connect.

I have tried all methods of RaiseError, PrintError and eval around the DBI->connect, but all still die with the install_driver(oracle) error.

Additionally, since the linkers cache the LIBPATH value before the script even executes (from what i understand), i can't unsetLIBPATH in a BEGIN block either.

Does anyone have a suggestion as to how I can deal with this other than using DBI->installed_versions ?

Editted by BazB: fixed formatting/code tags.

Replies are listed 'Best First'.
Re: DBI problems.
by astroboy (Chaplain) on Feb 28, 2004 at 09:12 UTC

    I'm not clear why you want to set up LIBPATH - is it for another application that requires it?

    What was your ORACE_HOME set to when you installed DBD::Oracle? Are you using the same setting when running your Perl script? I never have set LIBPATH, so I'm wondering if the Oracle environment variables are not quite right

      users (dbas) who execute this script will likely be logged in as oracle. user oracle sets LIBPATH in profile on login and it is required for some dba functions (it's a standard at our shop to set this).

      there are several oracle homes (and LIBPATH and other envs) that can be set depending on the db being accessed on the box. i can work with different ORACLE_HOME's no problem.

      sometimes i use the same environment, sometimes not. it seems as long as LIBPATH is unset, i don't have a problem.

      i want to be able to unset it, or handle the exception and print a notice to the user to unset it and run script again. that's where my problem is, i can't find a way to handle install_driver.

      thanks for the help!

        I'm not quite clear why LIBPATH is set. I set it (or LD_LIBRARY_PATH, depending on the OS), when I install Oracle or DBD::Oracle, but this is done manually just prior to installation. I do not set it in the profile, and it is not set for using Oracle on a day-to-day basis. I wonder if you are using some application that requires it. If you're not sure, why don't you unset it in your test system, and see if anything breaks
Re: DBI problems.
by esskar (Deacon) on Feb 28, 2004 at 02:48 UTC
    the problem is the it is not die but a Carp::croak i do not really know how to handle it correcly but why do u allow changing the LIBPATH anyway?