DBD-CSV
view release on metacpan or search on metacpan
lib/DBD/CSV.pm view on Meta::CPAN
=item csv_csv
X<csv_csv>
The attributes I<csv_eol>, I<csv_sep_char>, I<csv_quote_char> and
I<csv_escape_char> are corresponding to the respective attributes of the
I<csv_class> (usually Text::CSV_CS) object. You may want to set these
attributes if you have unusual CSV files like F</etc/passwd> or MS Excel
generated CSV files with a semicolon as separator. Defaults are
C<\015\012>", C<,>, C<"> and C<">, respectively.
The I<csv_eol> attribute defines the end-of-line pattern, which is better
known as a record separator pattern since it separates records. The default
is windows-style end-of-lines C<\015\012> for output (writing) and unset for
input (reading), so if on unix you may want to set this to newline (C<\n>)
like this:
$dbh->{csv_eol} = "\n";
It is also possible to use multi-character patterns as record separators.
For example this file uses newlines as field separators (sep_char) and
the pattern "\n__ENDREC__\n" as the record separators (eol):
name
city
__ENDREC__
joe
seattle
__ENDREC__
sue
portland
__ENDREC__
To handle this file, you'd do this:
$dbh->{eol} = "\n__ENDREC__\n" ,
$dbh->{sep_char} = "\n"
The attributes are used to create an instance of the class I<csv_class>,
by default Text::CSV_XS. Alternatively you may pass an instance as
I<csv_csv>, the latter takes precedence. Note that the I<binary>
attribute I<must> be set to a true value in that case.
Additionally you may overwrite these attributes on a per-table base in
the I<csv_tables> attribute.
=item csv_null
X<csv_null>
With this option set, all new statement handles will set C<always_quote>
and C<blank_is_undef> in the CSV parser and writer, so it knows how to
distinguish between the empty string and C<undef> or C<NULL>. You cannot
reset it with a false value. You can pass it to connect, or set it later:
$dbh = DBI->connect ("dbi:CSV:", "", "", { csv_null => 1 });
$dbh->{csv_null} = 1;
=item csv_bom
X<csv_bom>
With this option set, the CSV parser will try to detect BOM (Byte Order Mark)
in the header line. This requires L<Text::CSV_XS> version 1.22 or higher.
$dbh = DBI->connect ("dbi:CSV:", "", "", { csv_bom => 1 });
$dbh->{csv_bom} = 1;
=item csv_tables
X<csv_tables>
This hash ref is used for storing table dependent metadata. For any
table it contains an element with the table name as key and another
hash ref with the following attributes:
=over 4
=item o
All valid attributes to the CSV parsing module. Any of them can optionally
be prefixed with C<csv_>.
=item o
All attributes valid to DBD::File
=back
If you pass it C<f_file> or its alias C<file>, C<f_ext> has no effect, but
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:
$dbh->{csv_allow_whitespace} = 1;
$dbh->{csv_allow_loose_quotes} = 1;
$dbh->{csv_allow_loose_escapes} = 1;
See the C<Text::CSV_XS> documentation for the full list and the documentation.
=back
=head2 Driver specific attributes
=over 4
( run in 1.432 second using v1.01-cache-2.11-cpan-df04353d9ac )