view · edit · sidebar · attach · print · history

dbi 0.4.5 gem changes Ruby 1.9.1 to Ruby 1.9.2

<< CharacterEncodings | Index | Gd2 >>

Hash iteration breaks in Ruby 1.9.2

The Ruby dbi gem's Hash-Iteration breaks with Ruby 1.9.2. 1.9.1 did work. This is the fix of Chuck Remes. Thank you Chuck:

 /usr/lib/ruby/gems/1.9.1/gems/dbi-0.4.5/lib/dbi/columninfo.rb

change these lines

 - h.each_key do |k|
 + h.keys.each do |k|

also see

 http://groups.google.com/group/rubyinstaller/msg/e44ece960889f30e

Force the Array - works for Ruby 1.9.1 and Ruby 1.9.2

So in

 /usr/lib/ruby/gems/1.9.1/gems/dbi-0.4.5/lib/dbi/handles/statement.rb

we changed

 #fetched_rows.push(row)

to

 fetched_rows.push(row.to_a)

and it works! But we do not yet understand why it works for Ruby 1.9.2

How did we reach the conclusion

Why did I add 'to_a' method? (thought flow)

    * When I looked at the 'row' by 'p' method, it looked like an Array
    * I checked 'row' class by writing 'p row.class' then it showed 'DBI::Row'
    * I checked DBI::Row definition (/usr/lib64/ruby/gems/1.9.1/gems/dbi-0.4.5/lib/dbi/row.rb)
    * There is 'to_a' method defined
    * Also see: http://erik.hollensbe.org/docs/ruby-dbi/DBI/Row.html#method-i-to_a 

further

  • DBI::Row#@arr (Array) instannce is created around line:46-52 of /usr/lib64/ruby/gems/1.9.1/gems/dbi-0.4.5/lib/dbi/row.rb (DBI::Row class)
  • Somehow Ruby 1.9.1 creates a new Array instance but Ruby 1.9.2 does not create a new Array instance
view · edit · sidebar · attach · print · history
Page last modified on March 22, 2011, at 04:45 PM