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/