JetDriver and decimals

15 views
Skip to first unread message

Kristoffer Jansson

unread,
Mar 21, 2011, 11:42:57 AM3/21/11
to NHibernate Contrib - Development Group
I ran into a problem with the JetDriver and decimals a while ago when
working with MS Access databases, but I have no idea how to
contribute, so I'll just post it here.

The problem arises when you're trying to save a value of type decimal
in the database. Regardless of whether the designated column is a
double, or an actual decimal doesn't seem to matter. What happens is
that the decimal separator magically disappears. So saving '1.2' would
result in the value '12' in the database.

The fix is making decimals into doubles before saving to database.
Similar as to how the code already makes Int64 into Int32. This works
on both double and decimal columns.

I've no idea how to write an automated test to verify this, except
actually having a database lying around and try to store and read back
the data. Even then I'm not sure if the test could be used safely as
it's not very isolated. There may be some twisted environment of
drivers etc where the error wouldn't show up.

Anyway, I've seen this exact behavior on our systems as well as
customers, so it doesn't seem like it's only me :)

Here's a patch that fixes the problem:
http://www.itstod.se/files/jetdriver_decimal_to_double_fix.patch

Hadi Eskandari

unread,
Mar 21, 2011, 12:25:52 PM3/21/11
to nhc...@googlegroups.com
Have you tried this with latest build of JetDriver? I'll take a closer look on your patch and integrate if that fixes the problem you mentioned. By the way, current test suite uses an actual Jet database to run an automated test so writing one would be pretty simple.

Thanks for reporting this and sending in the patch.


--
You received this message because you are subscribed to the Google Groups "NHibernate Contrib - Development Group" group.
To post to this group, send email to nhc...@googlegroups.com.
To unsubscribe from this group, send email to nhcdevs+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nhcdevs?hl=en.


Kristoffer Jansson

unread,
Mar 21, 2011, 1:24:42 PM3/21/11
to NHibernate Contrib - Development Group
> Have you tried this with latest build of JetDriver?

I checked out the latest revision from https://nhcontrib.svn.sourceforge.net/svnroot/nhcontrib/trunk.
Is that the correct one?

> By the way, current test suite uses an actual Jet database to run an automated test so writing one would be pretty simple.

You're right. I took the liberty to write one:
http://www.itstod.se/files/decimaltest.patch

I'm not sure if it's ok to call:

public JetCommandFixture() : base(true) { }

But I didn't know how to create the table otherwise :)

// Kristoffer

Hadi Eskandari

unread,
Mar 21, 2011, 1:40:26 PM3/21/11
to nhc...@googlegroups.com
Yes that is the right place to get the latest source code.
I think you're on the right track, I'll check the patch more thoroughly and integrate it with the trunk version.

Hadi Eskandari

unread,
Mar 26, 2011, 4:56:08 AM3/26/11
to nhc...@googlegroups.com
Kristoffer,

I have slightly modified and applied your test, to the trunk version of JetDriver. It looks like this now, but the test is passing without applying your patch. I can even see in the Output window that the query ran on the db is like this:

NHibernate: INSERT INTO DecimalEntity (SimpleDecimal, SimpleDouble, NullableDecimal, NullableDouble, Id) VALUES (?, ?, ?, ?, ?);@p0 = 1.1, @p1 = 1.2, @p2 = 1.3, @p3 = 1.4, @p4 = 0

NHibernate: SELECT this_.Id as Id0_0_, this_.SimpleDecimal as SimpleDe2_0_0_, this_.SimpleDouble as SimpleDo3_0_0_, this_.NullableDecimal as Nullable4_0_0_, this_.NullableDouble as Nullable5_0_0_ from DecimalEntity this_ WHERE this_.Id = ?;@p0 = 0

and as you can see decimal points are all there in case of Decimal or Double data types. I know you mentioned the repro is tricky but I need a failing test here to make sure the bug is correctly patched. Could you help out? Did you run the test you provided before applying the patch and it failed?

Thanks,
Hadi

Kristoffer Jansson

unread,
Mar 28, 2011, 3:40:05 AM3/28/11
to NHibernate Contrib - Development Group
There's a bug in that test. You're testing against the original
entity, and not what you're getting from the database. If I test
against "readback", the test fail, see: https://gist.github.com/890120

// Kristoffer

On Mar 26, 10:56 am, Hadi Eskandari <h.eskand...@gmail.com> wrote:
> Kristoffer,
>
> I have slightly modified and applied your test, to the trunk version of
> JetDriver. It looks like this <https://gist.github.com/888143> now, but the

Hadi Eskandari

unread,
Mar 28, 2011, 4:13:20 AM3/28/11
to nhc...@googlegroups.com
Okay, my mistake, but the test still passes here. I basically run this and it passes. Does this fail on your end?

Kristoffer Jansson

unread,
Mar 28, 2011, 4:29:06 AM3/28/11
to NHibernate Contrib - Development Group
Yes, it fail.

I think I've found the problem. I thought I had tested all culture
related aspects of this, but I didn't dig deep enough. I'm running sv-
SE culture which uses a different decimal separator (comma instead of
dot). But changing the culture for the application thread is not
enough, you have to actually change your system wide settings and log
off/on first. When I did change my system settings to en-US and logged
off and on then ran the test, it passed.

So it seems like a culture related bug after all. Could you verify
this?

// Kristoffer

On Mar 28, 10:13 am, Hadi Eskandari <h.eskand...@gmail.com> wrote:
> Okay, my mistake, but the test still passes here. I basically run
> this<https://gist.github.com/890120>and it passes. Does this fail on

Hadi Eskandari

unread,
Mar 28, 2011, 4:38:17 AM3/28/11
to nhc...@googlegroups.com
Ah...that makes sense.
If you check the same fixture, there was another culture related problem with the dates. Think I'll be able to reproduce and fix it now.

Hadi Eskandari

unread,
Mar 29, 2011, 2:09:30 AM3/29/11
to nhc...@googlegroups.com
Just wanted to let you know that the bug was fixed in the trunk version.
Thanks for bearing with me.

Kristoffer Jansson

unread,
Mar 29, 2011, 3:42:06 AM3/29/11
to NHibernate Contrib - Development Group
Looking good. Awesome work. Thanks.

// Kristoffer

On Mar 29, 8:09 am, Hadi Eskandari <h.eskand...@gmail.com> wrote:
> Just wanted to let you know that the bug was fixed in the trunk version.
> Thanks for bearing with me.
>
Reply all
Reply to author
Forward
0 new messages