DBD-CSV
view release on metacpan or search on metacpan
examples/passwd.pl view on Meta::CPAN
use warnings;
use DBI;
my $dbh = DBI->connect ("DBI:CSV:");
$dbh->{csv_tables}{passwd} = {
sep_char => ":",
quote_char => undef,
escape_char => undef,
file => "/etc/passwd",
col_names => [qw( login password uid gid realname directory shell )],
};
my $sth = $dbh->prepare ("SELECT * FROM passwd");
$sth->execute;
my %fld;
my @fld = @{$sth->{NAME_lc}};
$sth->bind_columns (\@fld{@fld});
while ($sth->fetch) {
printf "%-14s %5d %5d %-25.25s %-14.14s %s\n",
@fld{qw( login uid gid realname shell directory )};
}
lib/DBD/CSV.pm view on Meta::CPAN
csv_class => "Text::CSV_XS",
csv_null => 1,
csv_bom => 0,
csv_tables => {
syspwd => {
sep_char => ":",
quote_char => undef,
escape_char => undef,
file => "/etc/passwd",
col_names => [qw( login password
uid gid realname
directory shell )],
},
},
RaiseError => 1,
PrintError => 1,
FetchHashKeyName => "NAME_lc",
}) or die $DBI::errstr;
but you may set these attributes in the DSN as well, separated by semicolons.
lib/DBD/CSV.pm view on Meta::CPAN
C<f_dir> and C<f_encoding> still have.
csv_tables => {
syspwd => { # Table name
csv_sep_char => ":", # Text::CSV_XS
quote_char => undef, # Text::CSV_XS
escape_char => undef, # Text::CSV_XS
f_dir => "/etc", # DBD::File
f_file => "passwd", # DBD::File
col_names => # DBD::File
[qw( login password uid gid realname directory shell )],
},
},
=item csv_*
X<csv_*>
All other attributes that start with C<csv_> and are not described above
will be passed to C<Text::CSV_XS> (without the C<csv_> prefix). These
extra options are only likely to be useful for reading (select)
handles. Examples:
lib/DBD/CSV.pm view on Meta::CPAN
There simplest way is:
use DBI;
my $dbh = DBI->connect ("dbi:CSV:", undef, undef, {
f_dir => "/etc",
csv_sep_char => ":",
csv_quote_char => undef,
csv_escape_char => undef,
});
$dbh->{csv_tables}{passwd} = {
col_names => [qw( login password uid gid realname
directory shell )];
};
$sth = $dbh->prepare ("SELECT * FROM passwd");
Another possibility where you leave all the defaults as they are and
override them on a per table basis:
require DBI;
my $dbh = DBI->connect ("dbi:CSV:");
$dbh->{csv_tables}{passwd} = {
eol => "\n",
sep_char => ":",
quote_char => undef,
escape_char => undef,
f_file => "/etc/passwd",
col_names => [qw( login password uid gid
realname directory shell )],
};
$sth = $dbh->prepare ("SELECT * FROM passwd");
=head2 Driver private methods
These methods are inherited from DBD::File:
=over 4
( run in 3.212 seconds using v1.01-cache-2.11-cpan-5735350b133 )