Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Handling DBD::OBDC error on a 'thread safe' class

by shonorio (Hermit)
on Nov 07, 2005 at 11:18 UTC ( #506289=perlquestion: print w/replies, xml ) Need Help??

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


I'm building a 'thread safe' class to running dbcc on MS SQL servers and translate the result on something readable and storeable. I got a example on DBD::ODBC package 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 class.

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,

my $ODBC = DBCCMessage->new(); $ODBC->open ( qq{dbi:ODBC:driver={SQL Server};Server=;databas +e=Northwind;Truted Connection=yes} ); my %s_ADO = $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 ) = @_; if ( $startString ) { my ( $stringConnection ) = map { $startString->{$_} if ( $_ =~ /conne +ction/i ) } keys %{$startString}; $self->open( $stringConnection ) if ( $stringConnection ); } } sub open { my ( $self, $conString ) = @_; $dbConnection{ident $self} = DBI->connect ( $conString, qq{}, qq{} ) or die qq{Can't connect to dat +abase, erro : $DBI::errstr}; } sub err_handler { my ( $self, $state, $msg, $nativeerr ) = @_; $msg =~ s/^(\[[\w\s:]*\])+//; push @{$objError{ident $self}}, $msg; return 0; } sub get_index_fragmentation { my $self = shift; my %return; my $ident = ident $self; my $sth = $dbConnection{$ident}->prepare(q{DBCC SHOWCONTIG (215751 +15, 1)}); $dbConnection{$ident}->{odbc_err_handler} = \&{$self->err_handler( +)}; $dbConnection{$ident}->{odbc_async_exec} = 1; $sth->execute(); } } 1;
Solli Moreira Honorio
Sao Paulo - Brazil

Replies are listed 'Best First'.
Re: Handling DBD::OBDC error on a 'thread safe' class
by renodino (Curate) on Nov 07, 2005 at 16:09 UTC
    You fail to mention precisely how its failing ? What version of (Perl, DBI, DBD::ODBC) you're using, and on what platform/OS ?

    I don't see anything in your code regarding threads (i.e., no threads->new(), threads::shared, lock(), etc), so I don't see what makes this "thread-safe" ?

    That said, have you considered DBIx::Threaded ? It might further simplify the thread-safety issue.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://506289]
Approved by Corion
Front-paged by jbrugger
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2023-01-27 14:25 GMT
Find Nodes?
    Voting Booth?

    No recent polls found