RE: [PEAR] Trying to loop through MDB rowset - proposed solution

From: Date: Sat, 09 Nov 2002 18:57:04 +0000
Subject: RE: [PEAR] Trying to loop through MDB rowset - proposed solution
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-10659@lists.php.net to get a copy of this message
Ah well ... Turns out I was not too tired to look at code tonight ... So I took a look at your code. But I think its not really what you want to do. MDB provides all the methods you need for all RDBMS, so there is no need to have different backends for each RDBMS Just use fetchInto() and freeResult(). The first will let you fetch one row after another and the other allows you to free a result set. Actually PEAR DB has something fairly similar. It was just that it was called as default and ate performance needlessly. But you can look there for a good example. I would recommend something like $res = new MDB_ResultObject($ressource_id); And this class calls MDB methods as needed. Regards, Lukas Smith smith@dybnet.de _______________________________ DybNet Internet Solutions GbR Reuchlinstr. 10-11 Gebäude 4 1.OG Raum 6 (4.1.6) 10553 Berlin Germany Tel. : +49 30 83 22 50 00 Fax : +49 30 83 22 50 07 www.dybnet.de info@dybnet.de > -----Original Message----- > From: Matt Friedman [mailto:matt@sprynewmedia.com] > Sent: Saturday, November 09, 2002 6:34 PM > To: smith@dybnet.de; pear-dev@lists.php.net > Subject: RE: [PEAR] Trying to loop through MDB rowset - proposed solution > > Hi Lucas, > > As I said I wanted to come up with a way to loop through record sets > without putting the set into a php array first. MDB doesn't seem to > provide methods that allow for this. > > I'm sending a rough implementation of an "iterator" class and its > associated factory method class for your consideration. Since the MDB > query method returns a resource id which points to a result set, we > don't have to rely on MDB to loop through the set. We can pass the > result id to another class which can then be responsible for providing > each item in the list. This hides the database implementation and allows > for all sorts of iteration classes to be written that could make use of > cursors etc... Looping backwards through the set is one example and so > on... > > A couple of other advantages: you can choose whether or not to free the > result at the end of the loop (see IsDone()) and if you don't free it, > you can re-use the iterator and loop through the same set again. The > default is to free the set. Also, this solution doesn't require changing > MDB at all. > > Anyway, I think my code is fairly self explanatory if not complete. > There needs to be lots more error checking and PEARifying if you want to > use it; but I wanted to contribute the idea. If you have any questions > please let me know. > > I hope this turns out to be helpful and useful. :) > > Matt Friedman > matt@SpryNewMedia.com > > > > > -----Original Message----- > > From: Matt Friedman [mailto:matt@sprynewmedia.com] > > Sent: Thursday November 7, 2002 4:58 PM > > To: smith@dybnet.de; pear-general@lists.php.net > > Subject: RE: [PEAR] Trying to loop through MDB rowset - > > > > Hi again Lukas, > > > > I've been thinking (ruminating) about this and have a solution (in my > > mind) about a way to satisfy this problem without having to touch MDB > at > > all. What I don't like about the current way is that MDB loops through > > the results and then I have to loop through the results again to > handle > > the data. Makes more sense to me to just loop once. > > > > I'll work on something and submit something to you - you can let me > know > > if it looks reasonable. Give me a day or so. > > > > Matt Friedman > > Web Applications Developer > > www.SpryNewMedia.com > > Phone: 416 992 5482 > > Email: matt@SpryNewMedia.com > > > > > > > > > -----Original Message----- > > > From: Lukas Smith [mailto:smith@dybnet.de] > > > Sent: Thursday November 7, 2002 2:42 PM > > > To: 'Matt Friedman'; pear-general@lists.php.net > > > Subject: RE: [PEAR] Trying to loop through MDB rowset - > > > > > > > From: Matt Friedman [mailto:matt@sprynewmedia.com] > > > > Sent: Thursday, November 07, 2002 8:32 PM > > > > To: smith@dybnet.de; pear-general@lists.php.net > > > > Subject: RE: [PEAR] Trying to loop through MDB rowset - > > > > > > > > Thanks very much Lucas. > > > > > > > > Is loading up a new array with the whole result set ok (as in > > > queryAll)? > > > > I had actually thought that using the Resource Id instead of > filling > > a > > > > result set object/array was more efficient. The impression I have > is > > > > that using a result id uses less memory. What about large result > > sets? > > > > This may not be a big issue - I'm just throwing it out there. But > > > that's > > > > actually why I was trying to avoid using queryAll if I could. > > > > > > > > What about the ability to _not_ free the result so that you can > > > continue > > > > to loop through using the resource id when you use fetchRow > etc...? > > > (via > > > > some flag or something?) > > > > > > > > Anyway, thanks again :) > > > > > > > > > > well hmmm ... > > > I ported this behavior from DB's get+() methods. > > > Recently there was the addition of autofree (automatically free a > > result > > > set when the end of the result set is reached). So maybe I shoud > > > re-examine this. Adding another flag is probably not a good idea > > because > > > most methods in MDB have so many parameters already due to the > > datatype > > > abstraction. > > > > > > Fetching everything at once will be faster I am quite sure as you > have > > > less function calls. Then again you might be right that is uses more > > > memory. > > > > > > Regards, > > > Lukas > > > > > > > > > -- > > > PEAR General Mailing List (http://pear.php.net/) > > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > > > > -- > > PEAR General Mailing List (http://pear.php.net/) > > To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.pear.dev (#10659) next »