开发者

DBD::CSV: Returns header in lower case

I've got a problem with the module DBD::CSV v0.30. Since a update to the newes version, all headers in the fetchrow_hashref generated hash are lower case instead of mixed case.

Finaly the data will be committed to a mysql database and the column header should be mixed case.

This is a snipet of my script using the DBD::CSV

my $csv_dbh = DBI->connect("DBI:CSV:f_dir=\.;csv_eol=\n");
$csv_dbh->{f_dir} = $ElementConfig->{_DIR} if defined($ElementConfig->{_DIR});
$csv_dbh->{csv_sep_char} = "$Seperator" if (defined($Seperator));
$csv_dbh->{csv_eol} = $csv_eol if (defined($csv_eol));
$csv_dbh->{csv_allow_whitespace} = $csv_allow_whitespace if (defined开发者_Python百科($csv_allow_whitespace));
my $CSV_Select;
unless (defined($ref_FullSQLSt)) { 
    // Standard "SELECT * FROM filname.txt"
    $CSV_Select = "SELECT ".${$ref_CSVSelect}." FROM $File ".${$ref_CSVWhere};
} else {
    $CSV_Select = ${$ref_FullSQLSt};
}
my $sth = $csv_dbh->prepare($CSV_Select);
my $res = $sth->execute();
while (my $row = $sth->fetchrow_hashref()) {
    my $PKeys = $index;
    if (defined($ElementConfig->{_FILES}->{$File}->{_dkey})) {
        my $NewPKeys = "";
        for my $key (split (/\s*\,\s*/,$ElementConfig->{_FILES}->{$File}->{_dkey})) {
            if (defined($row->{$key})) {
                $NewPKeys .= $row->{$key};
            }
        }
        $PKeys = $NewPKeys if ($NewPKeys);
    }

    unless (defined($DataHash->{$DBConfig->{TBLPREFIX} . $ElementConfig->{_FILES}->{$File}->{_dtbl}}->{$PKeys})) {
        $DataHash->{$DBConfig->{TBLPREFIX} . $ElementConfig->{_FILES}->{$File}->{_dtbl}}->{$PKeys} = $row;
        $index ++;
    }
}

This is a snipet of the csv file:

CELL    DATE    avgRxLevUl  avgRxLevDl  RXQUALUL0 
RTAL3D  08.12.2009 15:50    -96.25072834    -92.32065149    179594

Actual the fetchrow_hashref looks like this:

$var-> {
   'cell' => 'RTAL3D',
   'date' => '08.12.2009',
   'avgrxlevu1' => -96.25072834
   ...
}

I tried several things with the $sth->fetchrow_hashref() method. I used the parameter "NAME", "NAME_lc" and "NAME_uc". The first and the second convert the headers to lowercase and the third to uppercase.

Thanks for your help.


In case you're using q(SELECT * FROM tbl), SQL::Statement converts identifiers to lower case. This was necessary because of some internal issues in processing. To get the mixed case column names, query them by the name you need:

q(SELECT CELL, DATE, avgRxLevUl, avgRxLevDl, RXQUALUL0 FROM tbl).
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜