BigDecimal column type?

I was hoping 1.1 would provide a way to map SQL “decimal” column types
to BigDecimal values, since BigDecimal is part of the Ruby standard api
as of 1.8.

But I don’t see any support for that in the migration documentation, and
when I try to let Active Record do the mapping for me, it seems to
coerce the column into a Float (as the AwdwR book says).

Is it really there in 1.1 but I just don’t know what to do to tap into
it? Or is it still not part of ActiveRecord yet?

I’ve heard about Tobias’ “Money” plug-in but I’m not sure I want to go
that route unless I have to.

Storing money values should be very common - any shopping-cart style web
app will need to - but using floats can give rounding errors that can be
hard to spot (unlike the decimal type).

Any ideas? Maybe I’m missing something obvious?

Thanks!
Jeff

On Apr 01, 2006, at 2:54 am, Jeff C. wrote:

I was hoping 1.1 would provide a way to map SQL “decimal” column types
to BigDecimal values, since BigDecimal is part of the Ruby standard
api
as of 1.8.

Jeff

I missed this feature too - in fact it made Rails such a non-starter
at my company that I wrote a patch for ActiveRecord, which is
available at http://dev.rubyonrails.org/ticket/4274 . I wrote it
initially for Postgres and ported it to SQL Server (we are moving
from SQL Server to Postgres at work so they are the two databases I’m
familiar with). If you use either of these perhaps you’d give it a
try and let me know what you think. If I get time over the next few
weeks I’ll port it to Firebird and then MySQL. But really, you want
to be using Postgres for serious work :slight_smile:

Ashley

Ashley M. wrote:

If I get time over the next few
weeks I’ll port it to Firebird and then MySQL. But really, you want
to be using Postgres for serious work :slight_smile:

Hi Ashley,

Unfortunately I only use MySQL currently. If you do get a chance to
port it, just send an email to this list or to me directly and I’ll give
it a whirl.

Thanks a lot,
Jeff

On Saturday 01 April 2006 20:13, Jeff C. wrote:

Hi Ashley,

Unfortunately I only use MySQL currently. Â If you do get a chance to
port it, just send an email to this list or to me directly and I’ll give
it a whirl.

Thanks a lot,
Jeff
www.softiesonrails.com

Had a look at the MySQL adapter and it should be easy to get the numeric
precision and scale out of the database. If I’m not busy I’ll have a
look at
it over the weekend.

Ashley

On Tuesday 04 April 2006 14:47, kris wrote:

04/04/2006 14:47

Any news on this… very much needed!

Kris,

Last night I ported the decimal patch I’ve been working on to MySQL. If
you
want to try it you will need to freeze edge or gem into your application
directory, then apply the patch. Note that the PostgreSQL adapter has
recently been modified in the Rails trunk, so the patch will fail
against the
1.1 code (and I think 1.1.1 too). But this should not affect you using
MySQL.

Also, I still have to add two lines to SchemaDumper so it will dump the
precision and scale of decimals. This means that if you test an app
with
decimal columns, they will get the database default precision and scale.
I
didn’t notice this at first because I use Postgres, and that defaults to
using the maximum values available. However, SQL standard says the
scale
should default to 0, so you will end up with integers coming out of your
test
database. Just a heads up.

Here is the patch:

http://dev.rubyonrails.org/ticket/4274

Let me know if you have any issues with it (or even better post on the
trac
page)

Ashley

Ashley,

Cool! This answers my previous issue!

Angus

On Wednesday 12 April 2006 12:13, Angus McDonald wrote:

Ashley,

Cool! This answers my previous issue!

Angus

I’ve modified the patch to work as a plugin, if anyone is interested.
You can
download it here: http://www.ashleymoran.me.uk/sql_decimal_support.tgz

The patch has a full set of unit tests, but the plugin has none. I’ve
tried
it out with Postgres and it seems ok. SQL Server and MySQL may not work
if
I’ve copied something wrong.

Ashley

Any news on this… very much needed!

Ashley M. wrote:

On Saturday 01 April 2006 20:13, Jeff C. wrote:

Hi Ashley,

Unfortunately I only use MySQL currently. If you do get a chance to
port it, just send an email to this list or to me directly and I’ll give
it a whirl.

Thanks a lot,
Jeff
www.softiesonrails.com

Had a look at the MySQL adapter and it should be easy to get the numeric
precision and scale out of the database. If I’m not busy I’ll have a
look at
it over the weekend.

Ashley