tags:

views:

36

answers:

2

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 comited 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($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.

+3  A: 

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).

Best regards, Jens

Jens Rehsack
Thanks for your reply and solution, but in my opinion its more like a workaround than a solution. I want to use the statement "Select * From tbl" and the return should be the column names in mixed case as they were bevor the update.
Floopy-Doo
A: 

I've just hit the same problem. I had scripts which worked for several years, and now, out of the blue, they don't.

What is the solution? Revert to previous version of DBD

James