From: Robert Klemme Date: 2007-06-06T17:51:21+09:00 Subject: Re: Asking for style critics: Collecting the result of a query On 06.06.2007 09:44, Ronald Fischer wrote: >>> def fetch_result(querystring) >>> result=[] >>> qres = dbhandle.query(qstr) >>> while row = fetch_result.fetch_row # deliver next row >>> result.push row # add row to the result array - is this OK? >>> end >>> result # return result array >>> end > >> Your sample seems to be missing something: Where does "fetch_result" >> come into existence? And why don't you use "qres"? > > Sorry, my fault when condensing the original code to a form better > useful for discussing this issue (and during which I also renamed > variables to make understanding easier in this context). The > line should say: > > while row = qres.fetch_row .... > >> Attempting to answer your question, if you just append rows without >> modification you might as well do fetch_result.to_a. > > Given my corrections, I guess you would propose > > result = qres.to_a > > Right? But this would give: > > warning: default `to_a' will be obsolete > > and not return the result. The reason is that qres is, in my case, the > result object for a MySql query, so I think to_a is not applicable here. Hm, it does not implement to_a properly? I guess then it does not extend Enumerable as well. You can do this: qres.extend(Enumerable).to_a Kind regards robert