Skip Menu |

This queue is for tickets about the DBD-CSV CPAN distribution.

Report information
The Basics
Id: 52058
Status: resolved
Priority: 0/
Queue: DBD-CSV

People
Owner: HMBRAND [...] cpan.org
Requestors: sukria [...] sukria.net
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 0.22
Fixed in: 0.25



Subject: undef values are inserted as empty string instead of NULL values
Hi, I'm the author of Coat::Persistent, a small ORM that provides a CSV backend through DBD::CSV. Until version 0.22, DBD::CSV used to translate undef values in Perl as NULL values in SQL. That did make sense. Somewhere between version 0.22 and 0.25, DBD::CSV changed that behaviour, translating undef values in Perl as empty strings in SQL ( '' ). This causes a major break in Coat::Persistent, and even if I will fix my code in order not to crash on DBD::CSV > 0.22, I think this API break is not very welcome in DBD::CSV. I'd be very interesting in having some feedback from you on this topic, and would like to know if this change was wanted or not. Thanks a lot!
Subject: Re: [rt.cpan.org #52058] undef values are inserted as empty string instead of NULL values
Date: Wed, 25 Nov 2009 11:33:39 +0100
To: bug-DBD-CSV [...] rt.cpan.org
From: "H.Merijn Brand" <h.m.brand [...] xs4all.nl>
On Wed, 25 Nov 2009 04:45:02 -0500, "Alexis Sukrieh via RT" <bug-DBD-CSV@rt.cpan.org> wrote: Show quoted text
> I'm the author of Coat::Persistent, a small ORM that provides a CSV > backend through DBD::CSV. > > Until version 0.22, DBD::CSV used to translate undef values in Perl as > NULL values in SQL. That did make sense.
Not really, when looking from a CSV perspective, as CSV by default does not know of the concept of "UNDEFINED" or "NULL". Every field is a string, and there is no distinction between an empty string or, erm, and empty string. Show quoted text
> Somewhere between version 0.22 and 0.25, DBD::CSV changed that > behaviour, translating undef values in Perl as empty strings in SQL ( '' ).
Yes, strictly following the CSV specs. Show quoted text
> This causes a major break in Coat::Persistent, and even if I will fix my > code in order not to crash on DBD::CSV > 0.22, I think this API break is > not very welcome in DBD::CSV.
It is not an API break. It hasn't even been documented. It is a side-effect of the implementation. Show quoted text
> I'd be very interesting in having some feedback from you on this topic, > and would like to know if this change was wanted or not.
DBD::CSV uses Text::CSV_XS in the background, which supports blank_is_undef which is ingerently supported by DBD::CSV, and thus solves your problem instantly :) The new DBD::CSV makes it even easier to do this: --8<--- csv_null With this option set, all new statement handles will set "always_quote" and "blank_is_undef" in the CSV parser and writer, so it knows how to distinquish between the empty string and "undef" or "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; -->8--- -- H.Merijn Brand http://tux.nl Perl Monger http://amsterdam.pm.org/ using & porting perl 5.6.2, 5.8.x, 5.10.x, 5.11.x on HP-UX 10.20, 11.00, 11.11, 11.23, and 11.31, OpenSuSE 10.3, 11.0, and 11.1, AIX 5.2 and 5.3. http://mirrors.develooper.com/hpux/ http://www.test-smoke.org/ http://qa.perl.org http://www.goldmark.org/jeff/stupid-disclaimers/
Le Mer. Nov. 25 04:45:01 2009, SUKRIA a écrit : Show quoted text
> This causes a major break in Coat::Persistent, and even if I will fix my > code in order not to crash on DBD::CSV > 0.22, I think this API break is > not very welcome in DBD::CSV.
After taking a look to my code, it looks like this API break in DBD::CSV is a major blocker for Coat::Persistent. Anytime a NULL/undef value is inserted to the CSV database, DBD::CSV will translate it to an empty string. Coat::Persistent uses a Moose-like system to heavily define its data-types, and undef and '' are not the same. This break makes quite impossible to be able to distinguish an undef value from an empty string. Actually, this breaks quite all the code base of Coat::Persistent. Would it be possbile for DBD::CSV to fallback to what it did in 0.22 and translate undef values to NULL values?
Oh sorry, I didn't see your last reply, I'm going to try with this new option.
Le Mer. Nov. 25 05:56:02 2009, SUKRIA a écrit : Show quoted text
> Oh sorry, I didn't see your last reply, I'm going to try with this new > option.
Thanks, the csv_null => 1 option did fix all my problems. Sorry for the noise and thanks for the documentation pointer! Regards.