[Dbix-class] Pointless update on a date field
Matt S Trout
dbix-class at trout.me.uk
Thu Sep 13 14:37:31 GMT 2007
On Thu, Sep 13, 2007 at 09:52:30AM +0100, Richard Jones wrote:
> Matt S Trout wrote:
> >>All appears to be working fine, but I notice from the debugging SQL that
> >>the date field (dob) is always updated, even though the submitted value
> >>is identical to the stored value of the retrieved record, ie:
> >>
> >>UPDATE users SET dob = ?, gender = ? WHERE ( id = ? )
> >>
> >>I assume this is because I am using InflateColumn::DateTime on the date
> >>fields. If I dump $user->last_name I get a scalar, but $user->dob gives
> >>me a complex data structure (the DateTime object?). But I'm not sure why
> >>it is trying to update the date field. Presumably it's harmless, as the
> >>update would silently fail anyway?
> >
> >My suspicion would be that your DB isn't sending back the same datetime
> >string as is being saved, so the update always -thinks- the data's changed
> >even though the column values are equivalent.
> >
> >If so, the DateTime::Format::NameOfYourDb module probably needs patching.
> >
> >Fancy trying warn $obj->get_column('dob') before+after to see if I'm right?
>
> Result of 2 updates where only a non-date field should have been affected:
>
> PRE: 1934-12-21
> POST:1934-12-21
That one looks like it shouldn't have updated.
> PRE: 1927-09-09
> POST:1927-9-9
That one looks like what I was expecting.
> However, looking again at the docs it's quite possible that I'm not
> using the InflateColumn::DateTime function properly as I don't actually
> call inflate or deflate before updating or after searching (rather using
> my own function to transform dates to/from MySQL format, and/or using
> dob.strftime() function in the templates). Could that have anything to
> do with the inappropriate field update? Meanwhile I'll have a play with
> InflateColumn::DateTime.
You should just be dealing in DateTime objects and using the DBIC accessors;
the inflate/deflate will be transparent.
If you're using your own code to transform dates to/from mysql format you're
doing it wrong and any bugs are your problem. You can get the object DBIC
does to do it via $storage->datetime_parser.
--
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.shadowcat.co.uk/
More information about the DBIx-Class
mailing list