B
Brian Candler
The following test program works correctly with ruby-dbi-all-0.0.18 under
ruby-1.6.8, but not ruby-dbi-all-0.0.20 under ruby-1.8.0:
------------------------------------------------------------------
#!/usr/local/bin/ruby -w
require 'dbi'
LIMIT = 100
d = DBI.connect('dbi:Mysql:somedatabase','root','')
sql = "select col1,col2 from anytable"
rows = []
d.execute(sql) do |sth|
loop do
row = sth.fetch
p row # prints the right answer
break if row.nil?
rows << row.dup
break if rows.size >= LIMIT
end
end
p rows # prints the wrong answer
------------------------------------------------------------------
The problem is that the array 'rows' contains the last row repeated N times,
instead of N different rows. This is despite the use of 'row.dup'.
The object_id's of the elements of row are all different, but the contents
are the same.
I used mysql-ruby-2.4.4 in both cases.
Regards,
Brian.
ruby-1.6.8, but not ruby-dbi-all-0.0.20 under ruby-1.8.0:
------------------------------------------------------------------
#!/usr/local/bin/ruby -w
require 'dbi'
LIMIT = 100
d = DBI.connect('dbi:Mysql:somedatabase','root','')
sql = "select col1,col2 from anytable"
rows = []
d.execute(sql) do |sth|
loop do
row = sth.fetch
p row # prints the right answer
break if row.nil?
rows << row.dup
break if rows.size >= LIMIT
end
end
p rows # prints the wrong answer
------------------------------------------------------------------
The problem is that the array 'rows' contains the last row repeated N times,
instead of N different rows. This is despite the use of 'row.dup'.
The object_id's of the elements of row are all different, but the contents
are the same.
I used mysql-ruby-2.4.4 in both cases.
Regards,
Brian.