CC: | "Slava Zakovyrya" <SZakovyrya [...] parusinteractive.com>, "Peter Fitzgibbons" <pfitzgibbons [...] parusinteractive.com> |
Subject: | DBIx::Class::Storage::DBI::_connect() bug |
Date: | Sun, 23 Mar 2008 05:12:28 -0500 |
To: | <bug-DBIx-Class [...] rt.cpan.org> |
From: | "Zishan Ahmad" <ZAhmad [...] parusinteractive.com> |
I would have submitted the bug officially, but I'm too lazy right now to
register with Bitcard :-)
The current code in DBIx::Class::Storage::DBI::_connect() does not
suppress DBI::connect() error (i.e. bad credentials) output properly. I
see the error printed twice:
DBI connect('server=xxxxxxxx','xxxxxx',...) failed: Server message
number=4002 severity=14 state=1 line=0 server=xxxxxxxxx text=Login
failed.
OpenClient message: LAYER = (4) ORIGIN = (1) SEVERITY = (4) NUMBER =
(44)
Server xxxxxxxx, database
Message String: ct_connect(): protocol specific layer: external error:
The attempt to connect to the server failed.
at ../lib/DBIx/Class/Storage/DBI.pm line 826
DBIx::Class::ResultSet::find(): DBI Connection failed: Server message
number=4002 severity=14 state=1 line=0 server=xxxxxxxxx text=Login
failed.
OpenClient message: LAYER = (4) ORIGIN = (1) SEVERITY = (4) NUMBER =
(44)
Server xxxxxxxx, database
Message String: ct_connect(): protocol specific layer: external error:
The attempt to connect to the server failed.
This block in sub _connect
eval {
if(ref $info[0] eq 'CODE') {
$dbh = &{$info[0]}
}
else {
$dbh = DBI->connect(@info);
}
if($dbh && !$self->unsafe) {
my $weak_self = $self;
weaken($weak_self);
$dbh->{HandleError} = sub {
$weak_self->throw_exception("DBI Exception: $_[0]")
};
$dbh->{ShowErrorStatement} = 1;
$dbh->{RaiseError} = 1;
$dbh->{PrintError} = 0;
}
};
Should probably be more like:
eval {
if(ref $info[0] eq 'CODE') {
$dbh = &{$info[0]}
}
else {
if( !$self->unsafe ) {
my $weak_self = $self;
weaken($weak_self);
$info[3]->{HandleError} = sub {
$weak_self->throw_exception("DBI Exception: $_[0]")
};
$info[3]->{ShowErrorStatement} = 1;
$info[3]->{RaiseError} = 1;
$info[3]->{PrintError} = 0;
}
$dbh = DBI->connect(@info);
}
};
I think it may even be preferable to move that block of code ( if(
!$self->unsafe) { } ) to connect_info() to properly populate
_connect_info and _dbi_connect_info.
Regards.
Zishan Ahmad
Lead Engineer
Parus Interactive
Office: 847.919.7032
Message body is not shown because it is too large.