Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • DBD::ODBC (Score:3, Informative)

    We use DBD::ODBC and have been very happy. We connect like this (took me a while to work out so hope this helps...)

    my $dsn = join "", (
    "dbi:ODBC:",
    "Driver={SQL Server};",
    "Server=gort;",
    "UID=gpd;",
    "PWD=gpd;",
    "Database=gort_db",
    );

    my $user = 'gpd';
    my $passwd = 'gpd';

    my $db_options = {
    PrintError => 1,
    RaiseError => 1,
    AutoCommit => 0, #Use transactions
    };

    my $dbh =
    DBI->connect($dsn, $user, $passwd, $db_options)

    • You realize, of course, that with RaiseError set, your code will never hit that call to exit_msg(), die'ing before it gets there if there are any problems with the connect.
      • You realize, of course, that with RaiseError set, your code will never hit that call to exit_msg()

        That certainly hasn't been my experience - perhaps things have changed with recent versions of DBI. I understood that RaiseError was a property of the database handle object which wouldn't exist until the connect method had returned successfully. Errors during the connect itself are handled by returning undef and storing the error message in $DBI::errstr.

        • perhaps things have changed with recent versions of DBI.

          It probably was different at one time. Found this in the Change log:

          Changes in DBI 0.91,    10th December 1997

            NOTE: This fix may break some existing scripts:
            DBI->connect("dbi:...",$user,$pass) was not setting AutoCommit and PrintError!
            DBI->connect(..., { ... }) no longer sets AutoCommit or PrintError twice.
            DBI->connect(..., { RaiseError=>1 }) now croaks if connect fails.

          • Thanks very much for that piece of detective work. The 'or die' on my connect calls is obviously a piece of baggage I've been carrying far too long.

            • You must undergo the cleansing ritual of purging cargo cult code!!! :)

              Could be worse. I still deal with programs from people who wrote open FILE, "$filename" || die "Cant open file", leaving the apostrophe out of can't because they never understood the difference between single and double quotes, and the folklore persisted to nearly every programmer here except me that you couldn't use contractions in the die statement...

              --
              J. David works really hard, has a passion for writing good software, and knows many of the world's best Perl programmers