Hello,
I'm making my first foray into an application based on Class::DBI with MySQL as the backend DB. I'm loving everything about how easy C::DBI makes things through defining relationships, triggers, constraints ad naseum! :-) I've also been using DateTime::Format::MySQL to auto-inflate my date/datetime/timestamp columns into DateTime objects. One problem I've run into -- and the reason I'm posting this here -- is dealing with MySQL's special "NULL" datetime (represented as 0000-00-00 00:00:00). DateTime understandably refuses to accept this as a valid date.

Using SuperSearch, I came across one node here at the monestary (Re: Expand Class::DBI Field to DateTime Object) about this issue but the work around didn't seem very satisfactory (store the date values in another table and use a might_have relationship to inflate the to DateTime objects).

I've tried checking the value in my inflate method and returning undef if the date is the '0000-00-00 00:00:00' value. This seems to cause C::DBI to pass that undef value to DateTime->new() which obviously fails. I know I could just default it to DateTime->now() or maybe even DateTime->from_epoch(epoch=>0) but I'd rather be able to keep the idea of a "NULL" date somehow. Should I just subclass DateTime with my own object that can handle this special value?

I'm hoping someone else has come up against this issue before and can give me some advice on how to approach this issue.

Thanks in advance -- Brian

In reply to Class::DBI - MySQL - DateTime by bpphillips

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.