Bugs item #8790, was opened at 2007-02-21 09:43
You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=7857&aid=8790&group_id=2014

Category: AR-JDBC
Group: None
>Status: Closed
Resolution: Out of Date
Priority: 3
Submitted By: Nobody (None)
Assigned to: Nobody (None)
Summary: ActiveRecord-JDBC has issues storing Bignums

Initial Comment:
I have a MySQL database with a simple table:
mysql> describe widgets;
+----------+---------------------+------+-----+---------+----------------+
| Field    | Type                | Null | Key | Default | Extra          |
+----------+---------------------+------+-----+---------+----------------+
| id       | bigint(20) unsigned | NO   | PRI | NULL    | auto_increment |
| foobar   | varchar(255)        | YES  |     | NULL    |                |
| bleehort | bigint(20) unsigned | YES  |     | NULL    |                |
+----------+---------------------+------+-----+---------+----------------+
3 rows in set (0.00 sec)

The 'bleehort' column is an unsigned bigint, which allows it to store values 
from 0 to 18446744073709551615.  This number would be represented as a Bignum 
in Ruby, since Ruby specifies that Fixnum only goes up to 2**(wordsize-1) 
(2**63 on my system).

However, ActiveRecord-JDBC does not appear to handle trying to save a Bignum: 

~ $ irb
irb(main):001:0> require 'rubygems'
=> true
irb(main):002:0> require 'active_record'
=> true
irb(main):003:0> ActiveRecord::Base.establish_connection(:adapter => 'jdbc', 
:driver => 'com.mysql.jdbc.Driver', :url => 
'jdbc:mysql://localhost/mydatabase', :username => 'myusername', :password => 
'mypassword')
=> #<ActiveRecord::Base::ConnectionSpecification:0xd95674 
@adapter_method="jdbc_connection" ,@config={:password=>"mypassword", 
:adapter=>"jdbc", :username=>"myusername", 
:url=>"jdbc:mysql://localhost/mydatabase", :driver=>"com.mysql.jdbc.Driver"}>
irb(main):004:0> class Widget < ActiveRecord::Base
irb(main):005:1> end
=> nil
irb(main):006:0> a = Widget.new
=> #<Widget:0x64bcd3 @new_record=true ,@attributes={"foobar"=>nil, 
"bleehort"=>nil}>
irb(main):007:0> a.foobar = "blahblahblahfishcakes"
=> "blahblahblahfishcakes"
irb(main):008:0> a.bleehort = (2**64)
=> 18446744073709551616
irb(main):009:0> a.save
NativeException: java.lang.RuntimeException: Ruby "Bignum" object can not be 
allocated
        from ObjectAllocator.java:25:in 
`org.jruby.runtime.ObjectAllocator$1.allocate'
        from RubyObject.java:962:in `org.jruby.RubyObject.doClone'
        from RubyObject.java:950:in `org.jruby.RubyObject.rbClone'
        from null:-1:in `org.jruby.RubyObjectInvokerrbClone0.call'
        from FastInvocationCallback.java:49:in 
`org.jruby.runtime.callback.FastInvocationCallback.execute'
        from SimpleCallbackMethod.java:80:in 
`org.jruby.internal.runtime.methods.SimpleCallbackMethod.call'
        from RubyObject.java:473:in `org.jruby.RubyObject.callMethod'
        from RubyObject.java:417:in `org.jruby.RubyObject.callMethod'
        from EvaluationState.java:312:in 
`org.jruby.evaluator.EvaluationState.evalInternal'
        from EvaluationState.java:280:in 
`org.jruby.evaluator.EvaluationState.evalInternal'
        from EvaluationState.java:1195:in 
`org.jruby.evaluator.EvaluationState.evalInternal'
        from EvaluationState.java:158:in 
`org.jruby.evaluator.EvaluationState.eval'
        from DefaultMethod.java:157:in 
`org.jruby.internal.runtime.methods.DefaultMethod.internalCall'
        from AbstractMethod.java:64:in 
`org.jruby.internal.runtime.methods.AbstractMethod.call'
        from DefaultMethod.java:113:in 
`org.jruby.internal.runtime.methods.DefaultMethod.call'
        from RubyObject.java:473:in `org.jruby.RubyObject.callMethod'
... 1548 levels...
        from 
/Users/epowell/Development/jrubydev/jruby/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/active_record/base.rb:2035:in
 `attributes_with_quotes'
        from 
/Users/epowell/Development/jrubydev/jruby/lib/ruby/gems/1.8/gems/ActiveRecord-JDBC-0.2.2/lib/active_record/connection_adapters/jdbc_adapter.rb:12:in
 `attributes_with_quotes'
        from 
/Users/epowell/Development/jrubydev/jruby/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/active_record/base.rb:1813:in
 `quoted_column_names'
        from 
/Users/epowell/Development/jrubydev/jruby/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/active_record/base.rb:1813:in
 `create'
        from 
/Users/epowell/Development/jrubydev/jruby/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/active_record/callbacks.rb:254:in
 `create'
        from 
/Users/epowell/Development/jrubydev/jruby/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/active_record/timestamp.rb:39:in
 `create_with_timestamps'
        from 
/Users/epowell/Development/jrubydev/jruby/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/active_record/base.rb:1790:in
 `create_or_update'
        from 
/Users/epowell/Development/jrubydev/jruby/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/active_record/callbacks.rb:242:in
 `create_or_update_with_callbacks'
        from 
/Users/epowell/Development/jrubydev/jruby/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/active_record/base.rb:1546:in
 `save'
        from 
/Users/epowell/Development/jrubydev/jruby/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/active_record/validations.rb:752:in
 `save'
        from 
/Users/epowell/Development/jrubydev/jruby/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/active_record/transactions.rb:128:in
 `save_with_transactions'
        from (irb):1:in `transaction'
        from 
/Users/epowell/Development/jrubydev/jruby/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/active_record/transactions.rb:96:in
 `transaction'
        from 
/Users/epowell/Development/jrubydev/jruby/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/active_record/transactions.rb:121:in
 `transaction'
        from 
/Users/epowell/Development/jrubydev/jruby/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/active_record/transactions.rb:129:in
 `save_with_transactions'
        from (irb):1:in `binding'irb(main):010:0>


----------------------------------------------------------------------

Comment By: Charles Nutter (headius)
Date: 2009-02-24 00:30

Message:
Really old, no followup. Out of date.

----------------------------------------------------------------------

Comment By: Ola Bini (olabini)
Date: 2007-08-11 08:21

Message:
Is this still an issue?

----------------------------------------------------------------------

You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=7857&aid=8790&group_id=2014
_______________________________________________
Jruby-extras-devel mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/jruby-extras-devel

Reply via email to