From: Sven Suska Date: 2006-08-04T01:00:33+09:00 Subject: Re: Array#size empties the Array?? Yukihiro Matsumoto wrote: > Sven Suska writes: > > |Sorry, I had forgotten to give enough information: > > This is not enough. Could you show us a whole script to reproduce the > problem? Yes I know it would be useful, but it's hard to find and extract the relevant parts. > I am sure your expectation of "exactly same" fails > somewhere. Well, sorry to say that, but I think your assumption is not correct. Let's see if my new findings give anybody a clue. At first I tried a different ActiveRecord version - no difference. Then I put some debug printouts into AR and I found clearly different behaviour. I'll just give the raw output, even if I don't tell you what the printout statements were, you can see the difference clearly: 1. #length first: ================ ** RUBY_VERSION = "1.8.4" ** "ar-svs: args=[:all]" ** [:SVSAR_find_sql, "SELECT * FROM rkScGla WHERE (rkScGla.vsnr = 'GK_715') AND (rkScGla.komp = 'R1') AND (rkScGla.vtnr = 1) "] ** "tn=rkScGla" ** :vor_newtable ** :nach_newtable ** "tn=rkScGla" ** :vor_newtable ** :nach_newtable ** "tn=rkScGla" ** :vor_newtable ** :nach_newtable [:rks_length, 31] [:rks_size, 31] [:rks_class, Array] [:rks_item, #0.0, ...}>] [:rks_length, 31] [:rks_size, 31] 2. #size first: =============== ** RUBY_VERSION = "1.8.4" ** "tn=rkScGla" ** :vor_newtable ** :nach_newtable ** "tn=rkScGla" ** :vor_newtable ** :nach_newtable ** "tn=rkScGla" ** :vor_newtable ** :nach_newtable ** [:SVSAR_sel_1_sql, "SELECT count(*) AS count_all FROM rkScGla WHERE (rkScGla.vsnr = 'GK_715' AND rkScGla.komp = 'R1' AND rkScGla.vtnr = 1) " [:rks_size, 0] [:rks_length, 0] [:rks_class, Array] [:rks_item, nil] [:rks_length, 0] [:rks_size, 0] ---> This looks like a very exciting ActiveRecord hack!!! It looks like rks is something special in the beginning, that will be replaced by the real array as soon as methods are being sent to it. Well, whatever the explanation may be, it has become clear now, that this behaviour is caused by ActiveRecord, and so I should repost the issue in the rails forum. And now I understand why this issue has not bothered anybody before, it has only come up because my hand-written database-adapter is not yet able to execute the "SELECT count(*) ..." statement correctly. OK... Exciting day, today... Thank you all for your support Regards Sven -- Posted via http://www.ruby-forum.com/.