[Dbix-class] Re: RFC: Patch for InflateColumn::Datetime to handle
invalid date
Matt S Trout
dbix-class at trout.me.uk
Sat Jun 16 02:10:07 GMT 2007
On Fri, Jun 15, 2007 at 09:46:21AM -0600, Eric Waters wrote:
> > Any thoughts? What would you all like (if anything)
> > in terms of a solution for this. I can get some paid
> > time to work on this for us. Please don't say
> > "Postgresql", I don't have that option on this
> > contract.
>
> I'm not sure if this is the "best" way to handle it, but it's the way I've handled it. I don't know the best way to handle the error; I think I would rather see it return undef even though as has been mentioned MySQL isn't consistent on wether it's null or not. I think the alternative would be to return a pseudo-DateTime object that represents "0000-00-00" in some way.
>
> @@ -62,11 +63,21 @@ sub register_column {
> {
> inflate => sub {
> my ($value, $obj) = @_;
> - $obj->_datetime_parser->$parse($value);
> + return undef if ! defined $value;
> +
> + my $dt;
> + eval { $dt = $obj->_datetime_parser->$parse($value) };
> + #cluck $@ if $@;
> + return $dt;
> },
> deflate => sub {
> my ($value, $obj) = @_;
> - $obj->_datetime_parser->$format($value);
> + return $value if ! $value || ! ref($value);
> +
> + my $str;
> + eval { $str = $obj->_datetime_parser->$format($value) };
> + #cluck $@ if $@;
> + return $str;
> },
> }
> );
That's a cute workaround for MySQL being stupid.
Please submit it as a patch for DateTime::Format::MySQL - database specific
code has no place at all in InflateColumn::DateTime - the various databases
stupidities should be encapsulated behind the storage api ...
--
Matt S Trout Need help with your Catalyst or DBIx::Class project?
Technical Director Want a managed development or deployment platform?
Shadowcat Systems Ltd. Contact mst (at) shadowcatsystems.co.uk for a quote
http://chainsawblues.vox.com/ http://www.shadowcatsystems.co.uk/
More information about the Dbix-class
mailing list