[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: MySql::Result#each_hash deletes data

eagle eyes joe

9/28/2004 4:36:00 PM

Kent,

Thanks for your help. Are you saying that the data is still there in
the Result object, but I am pointing to the end and I need to rest the
pointer to the beginning? Can you give me an example of using
Result#row_seek?

Thanks again,

Joe.




In article <14F23C8D-0F59-11D9-8317-000A95C700E8@bellsouth.net>,
Kent Sibilev <ksibilev@bellsouth.net> wrote:

> No, this corresponds to the way Mysql C API works. Use
> Mysql::Result#row_seek to return to the beginning of the result set.
> You shouldn't treat Mysql::Result as a in-memory Enumerable object,
> because there are usually resources allocated on the server for each
> Mysql::Result instance.
>
> Cheers,
> Kent.
>
> On Sep 25, 2004, at 8:59 PM, eagle eyes joe wrote:
>
> > Greetings:
> >
> > You can only read a Mysql::Result object once because
> > each_key deletes the values as it reads them. This is unexpected and
> > I
> > think it should be fixed.
> >
> > This little program shows what I mean:
> >
> >
> > [Abba:/tmp] josephal% cat resulttest
> > #!/usr/bin/ruby
> >
> > require 'mysql'
> >
> > m = Mysql.new("localhost", "root", "", "Development")
> >
> > r = m.query("select * from processedfiles limit 5")
> >
> > r.each_hash { |row| print "#{row['name']}\n" }
> >
> > print "---------------------------------------\n"
> >
> > r.each_hash { |row| print "#{row['name']}\n" }
> >
> > print "------------------- -\nthis is the end\n"
> >
> >
> > [Abba:/tmp] josephal% resulttest
> > AD030220
> > AD030221
> > AD030228
> > AD030307
> > AD000428
> > ---------------------------------------
> > ------------------- -
> > this is the end
> > [Abba:/tmp] josephal%
> >
>
>
>