[Dbix-class] Inflation (DBIx::Class::InflateColumn) Troubles...

Christopher H. Laco claco at chrislaco.com
Sun May 6 01:52:04 GMT 2007


Jason Kohles wrote:
> I'm trying to track down a problem I'm having that seems to be an issue
> with DBIx::Class::InflateColumn.  I'm using InflateColumn::DateTime and
> InflateColumn::Currency, as well as some hand-built inflate/deflate
> calls that all seem to have similar problems.  It appears that in some
> circumstances the values assigned to inflated columns will not be
> deflated before being passed to the database, and I'm having a heck of a
> time figuring out why that is.  The minimal test case below uses
> InflateColumn::Currency simply because it's the easiest to see the
> problem there (since the inflated values will have dollar-signs that
> make it easy to see that they are still inflated)...

I'm assuming you're using the default currency class, which is
Data::Currency.

I know for sure that this is NOT supported:

    my $c =3D Data::Currency->new('$1.00');

The main reason being that figuring out what to parse out that string to
get a real numeric value is not exactly straight forward when it comes
to foreign currencies what may use unicode symbols, letters, and even
different currency separators other than "."

I'm not too versed on how DBIC defaltes  a column value that isn't even
an object instance, so I can't say what's really wrong...but if the
field really is a 'float', I'd assume passing in $ isn't going to work
either.

So, do your tests pass if you change the update calls to:

    $obj->update( { money =3D> 456.00 } );

?

The general rule of thumb when setting column values using the column
accessors or update() is this: always either pass an object or pass the
value EXACTLY as the database being used expects.

DateTime has the same issue:

If I do:

    update({ col =3D> DateTime->now });

deflate will get the correct format into the DB...

If I do:

    update({ col =3D> '1/2/2007' });

and I'm trying to update a database that doesn't grok that format, bad
things will happen.

So, in your case, either pass in the float (not as the string you have
with the currency symbol), or pass in new Data::Currency object instances.

-=3DChris

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 187 bytes
Desc: OpenPGP digital signature
Url : http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20070505/8e=
016480/signature.pgp


More information about the Dbix-class mailing list