Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^4: DBD::CSV works with text, but not numbers

by Tux (Canon)
on May 20, 2016 at 12:03 UTC ( [id://1163619]=note: print w/replies, xml ) Need Help??


in reply to Re^3: dbi::CSV works with text, but not numbers
in thread dbi::CSV works with text, but not numbers

Digging a bit deeper, just to satisfy my own curiosity (as I could not remember lower-casing the headers), here's the cause of your column name folding:

From the SQL::Statement manual pages:

· Wildcards are expanded to lower cased identifiers. This mig +ht confuse some people, but it was easier to implement. The warning in DBI to never trust the case of returned colu +mn names should be read more often. If you need to rely on identifie +rs, always use "sth->{NAME_lc}" or "sth->{NAME_uc}" - never rel +y on "sth->{NAME}": $dbh->{FetchHashKeyName} = "NAME_lc"; $sth = $dbh->prepare ("SELECT FOO, BAR, ID, NAME, BAZ FRO +M TABLE"); $sth->execute; $hash_ref = $sth->fetchall_hashref ("id"); print "Name for id 42 is $hash_ref->{42}->{name}\n"; See "FetchHashKeyName" in DBI for more information.

As select * from selects on a wildcard, this situation comes into effect. I'll add an explicit note to the docs of DBD::CSV.

Note in case of DBD::CSV that you can check what the driver's view on reality is by inspecting $dbh->{csv_tables}{tablename}{col_names}. My test showed me that this still holds the original folding.

Personally, I always use NAME_lc in all my database interfaces, so I never hit this problem.


Enjoy, Have FUN! H.Merijn

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1163619]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2024-04-24 19:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found