artist has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to use DBD::AnyData with Template Toolkit. Somehow it doesn't return any result. I have it working directly from perl, without any problem. Is there anyway I can debug it?

Template Code:

[% USE d = DBI(database = "dbi:AnyData", user = "", password = ""); d.dbh.func("t_labels", "CSV", "/tmp/demo_labels.csv", "ad_catalog") +; FOREACH item = d.query("SELECT id,name FROM t_labels"); item.id; " has "; item.name; END; %]
Working Code:
use DBI; my $dbh = DBI->connect('dbi:AnyData(RaiseError=>0):'); $dbh->func( 't_labels', 'CSV', '/tmp/demo_labels.csv', 'ad_catalog' ); my $query = qq!SELECT id,name from t_labels!; my $sth = $dbh->prepare($query); $sth->execute(); while ( my $row = $sth->fetchrow_hashref ) { print $row->{name}, "\n"; }
I am trying to figure out, what is wrong in the template code.
Thanks,
--Artist

Replies are listed 'Best First'.
Re: DBD:AnyData with TT
by Asim (Hermit) on Jun 16, 2006 at 11:32 UTC

    Template Toolkit debugging can be done with the DEBUG option. The TT docs on Template Options (Runtime) detail the option. I'd give examples to help, as I feel the docs are a little sparse as to implementation, but I've never used DEBUG. Sorry!

    In fact, what I usually use is TT's Dumper module to find out what's being sent to my template from my code, like:

    [% USE Dumper %] <hr /> [% Dumper.dump_html(chunk_of_data_that_isn't_working) %]

    That might work well for you. Does it at least give you ideas?

    ----Asim, known to some as Woodrow.

Re: DBD:AnyData with TT
by Joost (Canon) on Jun 15, 2006 at 18:58 UTC
      Thanks, but that should not be the issue. According to this message following code works fine.
      [% USE d = DBI(database = "dbi:AnyData:null", user = "", password = + ""); d.dbh.func("users", "Passwd", "/etc/passwd", "ad_catalog"); FOREACH user = d.query("SELECT username, homedir, GID FROM users +"); user.username; " has homedir of "; user.homedir; " and GID of "; user.GID; "\n"; END; %]
      --Artist
Re: DBD:AnyData with TT
by davidrw (Prior) on Jun 16, 2006 at 03:08 UTC
    As an alternative, Template::Plugin::Datafile (comes as part of TT) may be of interest (i recently found it and really liked it for some somple stuff):
    [% USE items = datafile('/tmp/dmeo_labels.csv', delim = ',') %] [% FOREACH item = items %] [% item.id %] has [% item.name %] [% END %]
Re: DBD:AnyData with TT
by Anonymous Monk on Jun 16, 2006 at 05:16 UTC
    Too cool to turn debugging on?