Hmm.. actually, rewriting both (and maybe this auotmagically fixes your problem?):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); };
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..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; }
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |