hi satya, great comments! thanx for the information. it might be a clever alternative to implement the "count(*)" functionality by means of a prepared (compiled) statement, if you need the number of results. the cursor will do the iteration job, the prep statement the fast initial counting.
marcus ________________________________ Von: Satya Komatineni <satya.komatin...@gmail.com> An: android-develop...@googlegroups..com Gesendet: Donnerstag, den 11. Dezember 2008, 17:45:32 Uhr Betreff: [android-developers] Re: How does a Cursor work? Taisa, Hopefully you have found some answers on this since you have posted. If you did find any numbers indicating one way or the other, I would like to know. I looked at some source code of Android to see what is under the hood. Here are some thoughts based on what I saw. The "Cursor" object is an interface that is allowing both forward and backward movement. In addition the interface also supports the "getCount()". Both seem to indicate that all rows might be read upfront or at the earliest moment. The implementation of this cursor interface using SQLiteCursor seem to be using a "windowing" concept to read a set of rows depending on the window you are in. So it is possible that moving forward in a cursor should be pretty efficient. However calling "getCount()" may force a complete read of the internal cursor. So semantics of the Cursor interface is not delineating a clear "forward only" and "random" access semantics. But I believe the implementation is efficient enough if you follow the forward only semantics. This implies reading "getCount" early on is not a good thing if you are trying to read every row and do something with it. It may not be a bad idea to wrap the cursor interface and don't expose the getCount() and random movement methods and make the contract explicit to the clients. Hope that helps. On Mon, Dec 8, 2008 at 1:51 PM, Taísa Cristina <taisa.san...@gmail.com> wrote: > Hi, > > when a database query retrieves a Cursor, what does it have in fact? I mean, > does it have the whole result set in memory or keep a kind of "pointer" to > each result row, and when I do cursor.moveToNext() it points to the next > row? Or anything else? > > I need to deal with a long list of data, and I really wanna know how > efficient is a Cursor retrieved from a database query. > > Thanks, > Taísa > > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---