Not sure about your primary question (though it seems like it's a db issue, not perl, from first glance of the error message) ... but you might be interested in SQL::Abstract
use SQL::Abstract; my $sa = SQL::Abstract->new; # in _lookup(): my $query = "SELECT $indy->{string} FROM $indy->{table} ". "WHERE $indy->{index}=$row->{$fieldName}"; my ($sql, @bind) = $sa->select( $indy->{table}, [$indy->{string}], { + $indy->{index} => $row->{$fieldName} } ); my ($val) = $db->selectrow_array( $sql, {}, @bind ); return $val; # in _show_bugs(): my ($query,@bind) = $sa->select('Bug', \@fieldset, {bugid=>[split( +/,/,$args)]} ); my $sth = $db->prepare( $query ); eval { $sth->execute(@bind); };
Hmm.. actually, rewriting both (and maybe this auotmagically fixes your problem?):
sub _show_bugs(){ my $args = shift; my @headers = map { "*$_*" } qw/ ID Title Priority Assignment Stat +e /; my $fmt = "| %s | %s | %s | %s | %s |\n"; my $sql =<<EOF; SELECT 'fog' || b.bugid, b.sTitle, p.sPriority, u.sFullName, s.sStatus FROM Bug b LEFT JOIN Priority p ON p.ixPriority = b.bugpri LEFT JOIN Persion_l u ON u.ixPerson = b.bugassign LEFT JOIN Status s ON s.ixStatus = b.bugstate WHERE b.bugid IN ($args) EOF my $db = _connect(); my $rows = $db->fetchall_arrayref($sql); # note: is slurping in a +ll rows return join '', map { sprintf $fmt, @$_ } \@headers, @$rows; }
This way should be much more efficient -- let the database do the lookup work for you instead of making a bunch of calls (note that _lookup() isn't needed)... It's also a lot clearer -- you can see just from reading the SQL what it's doing..
note: you may or may not want LEFT joins.. (probably not, but i put them so as not to modify functionality)
note: it would be better to do the $args w/placeholders

In reply to Re: Can get values from db but cannot get related values from the relevant lookup table by davidrw
in thread Can get values from db but cannot get related values from the relevant lookup table by yoyomonkey

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.