[Dbix-class] Re: Tests for MySQL's illustrious 0000-00-00

Aristotle Pagaltzis pagaltzis at gmx.de
Fri Jul 18 20:06:55 BST 2008


* J. Shirley <jshirley at gmail.com> [2008-07-18 18:10]:
> Here's a patch I wrote that will simply return undef if there
> is an exception inflating the date.

That seems like a weird approach. 0000-00-00 is a pseudo-NULL.
(An unnecessary and idiotic way of saying NULL, but whatever.)
It seems to me that such values should be tested for directly,
and undef returned in their place without even trying to inflate
them. You wouldn’t try to inflate real NULLs either, would you?

> I'm not fully convinced that eating the error is a good thing,

No, of course it’s not. When there’s a genuine error it needs to
bubble out.

> but I also don't want a ton of pollution in the logs.

Exactly. 0000-00-00 is not an error nor should it lead to any. It
should be treated just like a NULL.

This is the right thing to do in terms of database agnosticism
also: if you treat 0000-00-00 like NULL, the API will exhibit
consistent semantics regardless of whether you’re using MySQL
or a real database. In contrast, the applicability of a swallow-
errors-for-this-column option depends on whether you’re running
on MySQL or not. It’s a visible unbreak-me switch that needs to
flipped when moving between database engines.

Regards,
-- 
Aristotle Pagaltzis // <http://plasmasturm.org/>



More information about the DBIx-Class mailing list