iconara / cql-rb

Cassandra CQL 3 binary protocol driver for Ruby
106 stars 31 forks source link

Fixing encoding of decimals ending in .0 or 0.0 #115

Closed ahisbrook closed 10 years ago

ahisbrook commented 10 years ago

Found an error where storing a BigDecimal ending in .0 or 00.0 would not store/retrieve correctly. Traced this to the append_decimal method of CqlByteBuffer

Example: Encoding a BigDecimal of 1042342234234.0 would result in a decoded decimal of -57169393542.0 Encoding a BigDecimal of 12000.0 was unable to be decoded

iconara commented 10 years ago

Sorry, because you closed the first PR I assumed this was the same as #112, but it doesn't look like that.

iconara commented 10 years ago

Thanks again for the PR and for finding this bug. Good catch. If you fix the small comments I added to the diff I'll merge this as soon as I get the time.

Do you need a new gem release soon?

ahisbrook commented 10 years ago

Yes, I'll fix those. Thanks for the quick reply!

A new gem release would be great when you get a chance.

On Jul 3, 2014, at 1:50 PM, Theo Hultberg notifications@github.com wrote:

Thanks again for the PR and for finding this bug. Good catch. If you fix the small comments I added to the diff I'll merge this as soon as I get the time.

Do you need a new gem release soon?

— Reply to this email directly or view it on GitHub.

iconara commented 10 years ago

I can get one out tomorrow tonight or tomorrow morning.

ahisbrook commented 10 years ago

Awesome. Tomorrow whenever is great. I fixed those issues, let me know if you have any other comments.

On Jul 3, 2014, at 1:55 PM, Theo Hultberg notifications@github.com wrote:

I can get one out tomorrow tonight or tomorrow morning.

— Reply to this email directly or view it on GitHub.

iconara commented 10 years ago

Looking at this code now I realize how much of a hack it is. Can you help me come up with a better way of doing this without going through #to_s -> #gsub -> #to_i? I've been looking at the BigDecimal docs for a while now and can't see anything obvious, but it feels like there's a way to use BigDecial#to_r.

I'll merge this when I can, regardless, but it would be great to have something better for the future.

ahisbrook commented 10 years ago

It is pretty hacky. I'll look at the docs and try to come up with some alternate solutions.

On Jul 3, 2014, at 2:48 PM, Theo Hultberg notifications@github.com wrote:

Looking at this code now I realize how much of a hack it is. Can you help me come up with a better way of doing this without going through #to_s -> #gsub -> #to_i? I've been looking at the BigDecimal docs for a while now and can't see anything obvious, but it feels like there's a way to use BigDecial#to_r.

I'll merge this when I can, regardless, but it would be great to have something better for the future.

— Reply to this email directly or view it on GitHub.

iconara commented 10 years ago

Merged in 8d6790b076ec09a776be7db9638fb69504fd7116. v2.0.2 is now on RubyGems.