I'm trying make my wrapper for DBI (that makes all kinds of different data structures out of SQL query results) more object oriented looking. Here I want to make a new database handle thru my own function (and I manage to connect) - but then when I try to run a query through the runsql_returnString_NEW() function, perl has trouble figuring out where it should be calling prepare() from. I tried using SUPER like the Advanced Perl Programming book suggests, but obviously I'm doing something wrong. Can anyone help me? Is this just plain -not- doable? (Perish the thought.)

#!/usr/local/bin/perl use strict; use DBI; use lib "./"; use db_dave; my $q = "select count(*) from tablename"; my $err = "error selecting count from tablename"; my $dbhandle = new db_dave; my $result = $dbhandle->runsql_returnString_NEW($q, $err); print $result . "\n"; ############################################## # in db_dave.pm package db_dave; @ISA = qw(DBI); ################### sub new { my ($self) = @_; $self = DBI->connect('dbi:Oracle:foo', 'foo', 'foo') || die "Cant' + connect: $DBI:errstr"; print STDERR "connected \n"; bless $self, 'db_dave'; return $self; } ################### sub runsql_returnString_NEW { my ($self, $q, $err) = @_; $sth = $self->SUPER::prepare($q); $sth->SUPER::execute || &error($q, $err); my $returnstring; while (@array = $sth->SUPER::fetchrow) { $returnstring = $array[0]; } $sth->SUPER::finish; return $returnstring; } 1;




-mr.dunstan

In reply to 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.