Handling DBD::OBDC error on a "thread safe" class
am 07.11.2005 12:20:06 von shonorioHi,
I'm building a 'thread safe' class to running dbcc on MS SQL servers and =
translate the result on something readable and storeable. Jeff Urlwin hel=
ped-me about how can I handle the DBCC message and his example is working=
well on a single program, but I still in trouble where talk about my cla=
ss.
On code bellow, is a sample of how I'd like to get my class working, but =
I couldn't get the handle error as i want.
I have no more idea about how solve this problem. Maybe have no solution,=
or someone here can.
Thanks to much,
Solli M. Hon=F3rio
my $ODBC =3D DBCCMessage->new();
$ODBC->open ( qq{dbi:ODBC:driver=3D{SQL Server};Server=3D127.0.0.1;databa=
se=3DNorthwind;Truted Connection=3Dyes} );
my %s_ADO =3D $ODBC->get_index_fragmentation();
package DBCCMessage;
use Class::Std;
use Class::Std::Utils;
{
use DBI;
use strict;
my %dbConnection : ATTR;
my %recordSet : ATTR;
my %objError : ATTR;
sub BUILD {
my ( $self, $ident, $startString ) =3D @_;
if ( $startString ) {
my ( $stringConnection ) =3D map {
$startString->{$_} if ( $_ =3D~ /connec=
tion/i )
} keys %{$startString};
$self->open( $stringConnection ) if ( $stringConnection );
}
}
sub open {
my ( $self, $conString ) =3D @_;
$dbConnection{ident $self} =3D DBI->connect ( $conString,
qq{},
qq{}
) or die qq{Can't connect to database, er=
ro : $DBI::errstr};
}
sub err_handler {
my ( $self, $state, $msg, $nativeerr ) =3D @_;
$msg =3D~ s/^(\[[\w\s:]*\])+//;
push @{$objError{ident $self}}, $msg;
return 0;
}
sub get_index_fragmentation {
my $self =3D shift;
my %return;
my $ident =3D ident $self;
my $sth =3D $dbConnection{$ident}->prepare(q{DBCC SHOWCONTIG (2157511=
5, 1)});
$dbConnection{$ident}->{odbc_err_handler} =3D \&{$self->err_handler()=
};
$dbConnection{$ident}->{odbc_async_exec} =3D 1;
$sth->execute();
}
}
1;