Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

connect() doesnt set errstr when the DB driver is missing #161

Open
rwfranks opened this issue Oct 28, 2024 · 0 comments
Open

connect() doesnt set errstr when the DB driver is missing #161

rwfranks opened this issue Oct 28, 2024 · 0 comments

Comments

@rwfranks
Copy link

Transcribed verbatim from CPAN RT#127545, warts and all.

Thu Nov 01 14:15:30 2018 marshall.mills [...] gmail.com - Ticket created
Subject: connect() doesnt set errstr when the DB driver is missing

Date: Thu, 1 Nov 2018 18:15:19 +0000
To: [email protected]
From: Marshall Mills [email protected]

Hey everyone,

DBI->connect() doesn't set $DBI::errstr, at least when the DB driver is missing.

This cost me some time tracing down what I thought was a firewall
issue. But, it just turned out that the mysql driver was missing.

Linux 4.1.12-103.7.3.el7uek.x86_64
Perl v5.16.3

Expected output:

DBI::VERSION 1.642
DBI::errstr:  install_driver(uninstalledDriver) failed: Can't locate
DBD/uninstalledDriver.pm in @INC
Failed to correctly connect to the `example` database.

Actual output:

DBI::VERSION 1.642
Failed to correctly connect to the `example` database.

Thank you for your time,
Marshall

------------------------------------------------------------------------------------------
#!/usr/bin/perl

use strict;
use warnings;

use DBI;

print( "DBI::VERSION " . $DBI::VERSION  . "\n" );

my $databaseName = 'example';
my $server = 'data.example.com';
my $userName = 'admin';
my $password = 'Example code, please dont judge';

my $dataSource = "DBI:uninstalledDriver:database=$databaseName;host=$server";

my $dbConnection = undef;

# https://metacpan.org/pod/DBI#connect
# DBI->connect will die on a driver installation failure and will only
return undef on a connect failure,
# in which case $DBI::errstr will hold the error message. Use eval if
you need to catch the "install_driver" error.

eval
{
   $dbConnection = DBI->connect( $dataSource, $userName, $password,
{RaiseError=>1} );
};


if (defined( $DBI::errstr ))
{
   print( "DBI::errstr:  " . $DBI::errstr . "\n" );
}

if (!defined( $dbConnection ))
{
   print( "Failed to correctly connect to the `$databaseName` database.\n" );
   exit 1;
}

if (defined( $dbConnection ))
{
   $dbConnection->disconnect() || warn $dbConnection->errstr();
}

exit 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant