> However, if I nest this:
> 
> [% FOREACH tour = DBI.query( "SELECT * FROM tour_name ORDER BY tour_name_id D
> ESC" ) %]
> <H3>[% tour.tour_name_id %] : [% tour.tour_name %]</H3>
> 
> [% tdi = tour.tour_name_id %]
> [% FOREACH td =  DBI.query( "SELECT * FROM tour_date WHERE tour_date.tour_nam
> e_id = $tdi ORDER BY tourdate ASC")%]
> [% td.tourdate %]
> [% END %]
> [% END %]
> 
> I end up with only _two_ sets:

It's a bug.  The DBI plugin keeps the last statement handle (sth)
around in _STH (actually a Template::Plugin::DBI::Query object). The
new (inner) query overwrite _STH, which causes the first (outer)
Template::Plugin::DBI::Query's DESTROY method to be called, which
calls sth->finish on the outer loop.  You get two outer loops because
the Interator object caches the next value.

(The plugin keeps _STH around to support DBI.prepare followed
by DBI.execute, rather than query = DBI.prepare; query.execute;
Overwriting this static storage in the DBI object causes the
problem...)

Pending an actual fix, one workaround is to exhaust the iterator
on the first query by appending a get_all:

    [% FOREACH tour = DBI.query( "SELECT * FROM tour_name
                              ORDER BY tour_name_id DESC" ).get_all %]

Craig


Reply via email to