hello,

using DBI and Template Toolkit.

my webapp needs to fetch 100-300 rows with 5-6 columns and display them using Template. i don't want to reference each col by index from my template so i chose to fetch hashref. what i have is something like:

my $sth = $dbh->prepare_cached( $sql ); $sth->execute( @bind_vals ); $result = $sth->fetchall_hashref( $name ); $tt->process("result.tt", { result => $result })
but knowing that fetchall_hashref being the slowest among fetchall_arrayref and fetchrow_arrayref. i tried to use bind_columns and fetchrow_arrayref :
my ( %row , @rows ); $sth->bind_columns( \( @row{ @{$sth->{NAME_lc}} } ) ); while ( $sth->fetchrow_arrayref ) { my %row_copy = %row; push @rows, \%row_copy; } $tt->process("result.tt", { result => \@rows })
i got all result in nice AoH structure. but that defeats the purpose of bind_columns.

the DBI example of using bind_columns are fine as it prints out the fetched result in each loop. I can't do that and still use my template.

so my question is how do you use bind_columns with Template that require you to collect all results first?

UPDATE: my last sentence is bit misleading. i am wondering if there are better way to achive the same goal?


In reply to DBI output and Template Toolkit by Qiang

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.