in reply to problems wrapping DBI
Don't hardcode the classname. This will break inheritance, if you ever need it. Also, you weren't using strict in your package. Shame on you! :)
package db_dave; use strict; use DBI; use vars qw/ @ISA /; @ISA = qw/DBI/; sub new { my $class = shift; my $dbh = DBI->connect('dbi:Oracle:foo', 'foo', 'foo', { RaiseErro +r => 1 }) || die "Cant' connect: $DBI::errstr"; my $data = { _dbh => $dbh }; bless $data, $class; return $data; } sub runsql_returnString_NEW { my ($self, $q, $err) = @_; my $dbh = $self->{ _dbh }; my $sth = $dbh->prepare($q); $sth->execute || &error($q, $err); # <- why do you have a regular +function in an OO module? my $returnstring; while (my @array = $sth->fetchrow) { # ?? You're overwriting this every time :( # I can't tell what type of data structure you want $returnstring = $array[0]; } $sth->finish; return $returnstring; }
That should give you a start (though the code is untested). It needs a lot of work.
Cheers,
Ovid
Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: (Ovid) Re: problems wrapping DBI
by mr.dunstan (Monk) on Dec 17, 2001 at 23:27 UTC |