Thanks Ovid - you've given me some great perl nuggets that helped really explain how to work object oriented coding in perl! I figured since this was so helpful to me, I'd post my code, fixed up, since you posted on this thread, maybe this can help someone else. (I personally am going to use this stuff for quick and dirty data cleanup tasks...)

You guys were right about reinventing the wheel, I'm sure there are much better modules out there that would be better for maintainability's sake - I just wanted to do this as an exercise and got exactly what I wanted!

Thanks again...
package db_dave; use strict; use DBI; use vars qw/ @ISA /; @ISA = qw/DBI/; sub new { my $class = shift; my ($db, $username, $password) = @_; if ($password eq "") { print STDOUT "## enter password for " . $username . "\@" . $db + . ": "; $password = <STDIN>; chomp $password; if ($password eq "") {die;} } my $dbh = DBI->connect("dbi:Oracle:" . $db, $username, $password, +{ RaiseError => 1 }) || die "Cant' connect: $DBI::errstr"; my $data = { _dbh => $dbh }; bless $data, $class; print STDERR "\n## connected \n"; return $data; } sub disconnect { my ($self, $q, $err) = @_; my $dbh = $self->{ _dbh }; $dbh->disconnect; print STDERR "\n## disconnected \n\n"; return; } sub runsql_string { my ($self, $q, $err) = @_; my $dbh = $self->{ _dbh }; my $sth = $dbh->prepare($q); print STDERR "\n## runsql_string: $q \n"; $sth->execute || die; my $returnstring; my @array; while (@array = $sth->fetchrow) { $returnstring = $array[0];} my $stringcount = @array; if ($stringcount > 1) { die; } $sth->finish; if ($::DEBUG) { print STDERR "[0] " . $returnstring . "\n"; } return $returnstring; } =begin testing use strict; use DBI; use lib "./"; use db_dave; $::DEBUG = "1"; # prints query results my $dbh = new db_dave("foo", "foo", "foo"); my $err = "error"; $q = "select count(*) from table"; $dbh->runsql_string($q, $err) . "\n"; $dbh->disconnect; =end testing


-mr.dunstan

In reply to Re: (Ovid) Re: problems wrapping DBI by mr.dunstan
in thread problems wrapping DBI by mr.dunstan

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.