Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

[mod_perl] Class::DBI temp columns missing on first result

by koyrist (Novice)
on Sep 06, 2012 at 08:05 UTC ( #992031=perlquestion: print w/ replies, xml ) Need Help??
koyrist has asked for the wisdom of the Perl Monks concerning the following question:

Okay, getting a strange problem with Class::DBI. Using the example from the usage.
Music::Artist->set_sql(most_cds => qq{ SELECT artist.id, COUNT(cd.id) AS cds FROM artist, cd WHERE artist.id = cd.artist GROUP BY artist.id ORDER BY cds DESC LIMIT 10 }); my @artists = Music::Artist->search_most_cds();
I've also setup the temp column in Music/Artist.pm
__PACKAGE__->columns(TEMP => qw/cds/);
Everything appears to be fine and if I execute the SQL directly in the database I get the appropriate results with the counts that are correct. However, when the perl code spits out the data it appears to be missing the count (temporary cds column) on the first result. I've confirmed this by using Data::Dumper and this is what I'm seeing on my end (edited to match example).
$VAR1 = bless( { '__triggers' => {}, '_class_trigger_results' => [], ' +id' => '1' }, 'Music::Artist' ); $VAR2 = bless( { '__triggers' => {}, '_class_trigger_results' => [], ' +cds' => '2', 'id' => '2' }, 'Music::Artist' );
It's really late and that may have something to do with why I'm stumped but it's not making any sense what-so-ever.

UPDATE:
This only appears to be happening in mod_perl. I'm continuing to investigate. Any ideas, tips, feedback is appreciated.

-- koyrist

Comment on [mod_perl] Class::DBI temp columns missing on first result
Select or Download Code
Re: Class::DBI temp columns missing on first result
by pvaldes (Chaplain) on Sep 06, 2012 at 11:25 UTC
    "most_cds" is the name of your query. Why are you using "search_most_cds" in the array line?
Re: [mod_perl] Class::DBI temp columns missing on first result
by koyrist (Novice) on Sep 06, 2012 at 14:16 UTC
    Well it appears that when I request iterators instead of an array it comes through properly. I'm not sure why this is happening.
    my $artists = Music::Artist->search_most_cds();
    instead of
    my @artists = Music::Artist->search_most_cds();

    -- koyrist

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://992031]
Approved by Corion
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (15)
As of 2014-07-11 16:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (232 votes), past polls