@@ -127,7 +127,7 @@ sub init_valid_attributes {
127
127
128
128
class tables in csv_in out csv_out skip_first_row
129
129
130
- null sep quote escape
130
+ null sep quote escape bom
131
131
) };
132
132
133
133
$dbh -> {csv_readonly_attrs } = { };
@@ -197,6 +197,8 @@ sub bootstrap_table_meta {
197
197
$meta -> {csv_eol } ||= $dbh -> {csv_eol } || " \r\n " ;
198
198
exists $meta -> {csv_skip_first_row } or
199
199
$meta -> {csv_skip_first_row } = $dbh -> {csv_skip_first_row };
200
+ exists $meta -> {csv_bom } or
201
+ $meta -> {csv_bom } = exists $dbh -> {bom } ? $dbh -> {bom } : $dbh -> {csv_bom };
200
202
$self -> SUPER::bootstrap_table_meta ($dbh , $meta , $table );
201
203
} # bootstrap_table_meta
202
204
@@ -286,6 +288,12 @@ sub open_data {
286
288
: exists $meta -> {col_names } ? 0 : 1;
287
289
defined $meta -> {skip_rows } or
288
290
$meta -> {skip_rows } = $skipRows ;
291
+ if ($meta -> {csv_bom }) {
292
+ my @hdr = $attrs -> {csv_csv_in }-> header ($meta -> {fh }) or
293
+ croak " Failed using the header row: " .$attrs -> {csv_csv_in }-> error_diag;
294
+ $meta -> {col_names } ||= \@hdr ;
295
+ $skipRows = 0 if $skipRows ;
296
+ }
289
297
if ($skipRows --) {
290
298
$array = $attrs -> {csv_csv_in }-> getline ($meta -> {fh }) or
291
299
croak " Missing first row due to " .$attrs -> {csv_csv_in }-> error_diag;
@@ -546,27 +554,28 @@ The preferred way of passing the arguments is by driver attributes:
546
554
547
555
# specify most possible flags via driver flags
548
556
$dbh = DBI->connect ("dbi:CSV:", undef, undef, {
549
- f_schema => undef,
550
- f_dir => "data",
551
- f_dir_search => [],
552
- f_ext => ".csv/r",
553
- f_lock => 2,
554
- f_encoding => "utf8",
555
-
556
- csv_eol => "\r\n",
557
- csv_sep_char => ",",
558
- csv_quote_char => '"',
559
- csv_escape_char => '"',
560
- csv_class => "Text::CSV_XS",
561
- csv_null => 1,
562
- csv_tables => {
563
- info => { f_file => "info.csv" }
564
- },
565
-
566
- RaiseError => 1,
567
- PrintError => 1,
568
- FetchHashKeyName => "NAME_lc",
569
- }) or die $DBI::errstr;
557
+ f_schema => undef,
558
+ f_dir => "data",
559
+ f_dir_search => [],
560
+ f_ext => ".csv/r",
561
+ f_lock => 2,
562
+ f_encoding => "utf8",
563
+
564
+ csv_eol => "\r\n",
565
+ csv_sep_char => ",",
566
+ csv_quote_char => '"',
567
+ csv_escape_char => '"',
568
+ csv_class => "Text::CSV_XS",
569
+ csv_null => 1,
570
+ csv_bom => 0,
571
+ csv_tables => {
572
+ info => { f_file => "info.csv" }
573
+ },
574
+
575
+ RaiseError => 1,
576
+ PrintError => 1,
577
+ FetchHashKeyName => "NAME_lc",
578
+ }) or die $DBI::errstr;
570
579
571
580
but you may set these attributes in the DSN as well, separated by semicolons.
572
581
Pay attention to the semi-colon for C<csv_sep_char > (as seen in many CSV
@@ -956,6 +965,16 @@ reset it with a false value. You can pass it to connect, or set it later:
956
965
957
966
$dbh->{csv_null} = 1;
958
967
968
+ =item csv_bom
969
+ X<csv_bom>
970
+
971
+ With this option set, the CSV parser will try to detect BOM (Byte Order Mark)
972
+ in the header line. This requires L<Text::CSV_XS> version 1.22 or higher.
973
+
974
+ $dbh = DBI->connect ("dbi:CSV:", "", "", { csv_bom => 1 });
975
+
976
+ $dbh->{csv_bom} = 1;
977
+
959
978
=item csv_tables
960
979
X<csv_tables>
961
980
0 commit comments