in reply to Using DBD::CSV with Template::Plugin::DBI

For the filename, it may work to use a delimited identifier, e.g.
SELECT * FROM "c:/projekte/vdx/daten/users.txt" WHERE ...
As for the column names, I *think* you can specify those in the connect string driver params with csv_col_names. If not, ask me again there are more evil ways. :-)

Replies are listed 'Best First'.
Re^2: Using DBD::CSV with Template::Plugin::DBI
by holli (Abbot) on Aug 26, 2005 at 10:19 UTC
    Thanks, jZed. That works. As it turns out the plugin automatically takes the first line of the file and uses it for the fieldnames. Any way to avoid that? It can't be evil enough. :)


    holli, /regexed monk/
      Template::Plugin::DBI is on my list of modules to check out, but I've not yet worked with it. Does it allow you to specify a \%attr in the connect? If so, then this should work:
      [% USE DBI( 'dbi:CSV:',undef,undef, { RaiseError => 1 , csv_tables => { users => { file => 'c:/projekte/vdx/daten/users.txt' , eol => "\n" , col_names => ['id','name'] } } } ) -%]
      If the module doesn't support setting \%attrs in the connect string, does it allow you to pass a pre-defined $dbh? If it supports neither, that seems pretty lame. That would be an issue which impacts more than DBD::CSV. OTOH in order to support \%attrs in a template probably requires a string eval which is pretty lame also. (Please don't take this as a criticism of the module, it's more of general remark on modules that support DBI connections but don't support setting \%attrs during connection). Hmm, a thought - if the templating plugin uses YAML, it could avoid string eval.