#1378 new
Rafał Michalski

dm-aggregates with oracle invalid calculations

Reported by Rafał Michalski | July 29th, 2010 @ 11:15 AM

All aggregate functions (count, min, max, avg) returns inappropriate values while connecting with oracle adapter.

Oracle OCI adapter returns values of all aggregate functions as BigDecimal.

    conn = OCI8.new('user','***','Oracle1')
    conn.exec('SELECT COUNT(*) FROM "SOME_TABLE"') {|r| puts r.first.inspect}

Then the return values are internally converted by DataMapper to strings and then again to numbers.
So e.g. for count:

    #=> 0
    #<BigDecimal:8e68fc0,'0.1224E4',4(8)> (to_s) => "0.1224E4" => (to_i) => 0

At first BigDecimal gets converted to String ("0.1224E4") and then to Integer (0).

I don't know if the problem is with dm-aggregates itself or rather at oracle-adapter.

As a workaround for 'count' to get working i've made change in dm-aggregates/adapters/dm-do-adapter.rb

      def count(property, value)


      def count(property, value)

now i'm getting what i've expected:

    #=> 1224

Comments and changes to this ticket

  • Aaron Qian

    Aaron Qian June 19th, 2012 @ 05:23 PM

    • Tag changed from count, dm-aggregates, oracle to count, dm-aggregates, oracle

    I'm seeing this as well. I'm monkey patching in my project as suggested by Rafał Michalski, and it is working so far.

    Is there any plan to fixed this? This ticket has been 2 years old. Let me know if there is anything I can help to make this ticket go away! :)

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

People watching this ticket