[android-developers] Re: Querys involving more than one table of Contatcs Content Provider
I've written my own FilteredCursor that filters rows away from one cursor, by joining it with another (uses CursorJoiner internally). It suits my needs and is not quite general. The sort ASC presumption is a big downside. It's in the source code for my Collectionista project (revision 48, net.lp.collectionista.techserv.providers.FilteredCursor): http://bazaar.launchpad.net/%7Epjv/collectionista/trunk/download/48/filteredcursor.java-20081215002110-blupm1dk5m7h1z4a-2/FilteredCursor.java?file_id=filteredcursor.java-20081215002110-blupm1dk5m7h1z4a-2 It doesn't yet fully work though. Some issues I am encountering/have encountered: - The behaviour of CursorWrapper is not as documented (http:// code.google.com/p/android/issues/detail?id=1538). - Several of the classes offered aren't general at all, but very restricted, which is a bit of a disappointment: CursorWrapper, CursorJoiner, and the whole Cursor/CursorFactory infrastructure in general. The fact that it's not easy to create a new Cursor or to duplicate one. - I'm currently struggling with some random behaviour in my FilteredCursor, which I think could be related to concurrency. The ListAdapters in my UI that use the FilteredCursor seem to fail to get any information out of it sometimes. I did think about requery() etc. I'm a bit out of my wits on how to make all this work exactly as a regular cursor (for concurrency etc.) and it isn't documented perfectly either. Thanks anyway for considering, Mark, and I'm sure you'll be able to provide us with a more general example in your book soon. On 14 dec, 17:29, Mark Murphy mmur...@commonsware.com wrote: pjv wrote: Would you please share your custom solutions (in code) for reuse? Alas, my implementation was made under contract for another firm, so I cannot release it at this time. I'll see about rewriting it at some point, perhaps as part of a chapter in my upcoming Advanced Android book. I can't guarantee a timetable, though. -- Mark Murphy (a Commons Guy)http://commonsware.com _The Busy Coder's Guide to Android Development_ Version 1.9 Published! --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[android-developers] Re: Querys involving more than one table of Contatcs Content Provider
On Dec 14, 4:23 pm, pjv ezelsping...@gmail.com wrote: Would you please share your custom solutions (in code) for reuse? Sure - take a look at jarkman.co.uk/code/ JoiningAndFilteringCursors.zip There are two CursorWrapper derived classes in there, FilteringCursor and JoiningCursor. FilteringCursor leaves out rows, and JoiningCursor adds colums. Then there are two subclasses of JoiningCursor, one which uses a SQL filter to identify the extra data to add (JoiningCursorFilter - sorry for the bemusing name), and one which uses a URI-appending method (JoiningCursorUri). It would be easy to make more specific subclasses which got the extra data from some other source of your own, not from a cursor. And there are two example filters to use with FilteringCursor, CursorFilterGotAValue and CursorFilterInt. Again, it should be easy to write more specific filters for your own needs. FilteringCursor can be a performance problem, because it needs to do all its filtering before it can return from getCount(). I can't see any way to get round that. If you can, please let me know! :-) Thanks, Richard --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[android-developers] Re: Querys involving more than one table of Contatcs Content Provider
Richard, Mark, Would you please share your custom solutions (in code) for reuse? CursorJoiner doesn't do very much and doesn't seem to be able to give you a new joint Cursor back eventually. I think a lot of people could benefit from some code reuse here. Thanks, pjv On 6 dec, 09:53, jarkman jark...@gmail.com wrote: Mark - thanks for the suggestion. I ended up making a couple of general-purpose CursorWrapper subclasses, one for joining two providers one for filtering a provider (with a callback to define the desired rows). They certainly seem to work, and they make the calling code very tidy. I do still have some performance issues to deal with, but I'm sure they will respond to tweakery. Richard On Nov 26, 12:27 am, Mark Murphy mmur...@commonsware.com wrote: jarkmanwrote: I'd love to make a cursor which also included the name of the person, but as far as I know there is no way to do that with a single query. That's probably true. That is, as far as I can tell, there's no way to do a join via the content provider interface, and permissions prevent us from accessing the contacts database directly via SQL calls. I really hope somebody can prove me wrong! I will be dealing with a somewhat similar situation later this week, when I attempt to join data from a ContentProvider and a SQLite database. Since what I want in the end is a Cursor, the approach I am trying is to use a custom CursorWrapper subclass. It will get handed the Cursor from the ContentProvider and will fold in the data from the SQLite database on demand as the relevant values are requested. Caching gets a mite tricky (gotta remember to flush the cache on requery(), for example), but I see no reason it won't work. -- Mark Murphy (a Commons Guy)http://commonsware.com _The Busy Coder's Guide to Android Development_ Version 1.4 Published! --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[android-developers] Re: Querys involving more than one table of Contatcs Content Provider
pjv wrote: Would you please share your custom solutions (in code) for reuse? Alas, my implementation was made under contract for another firm, so I cannot release it at this time. I'll see about rewriting it at some point, perhaps as part of a chapter in my upcoming Advanced Android book. I can't guarantee a timetable, though. -- Mark Murphy (a Commons Guy) http://commonsware.com _The Busy Coder's Guide to Android Development_ Version 1.9 Published! --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[android-developers] Re: Querys involving more than one table of Contatcs Content Provider
Mark - thanks for the suggestion. I ended up making a couple of general-purpose CursorWrapper subclasses, one for joining two providers one for filtering a provider (with a callback to define the desired rows). They certainly seem to work, and they make the calling code very tidy. I do still have some performance issues to deal with, but I'm sure they will respond to tweakery. Richard On Nov 26, 12:27 am, Mark Murphy [EMAIL PROTECTED] wrote: jarkmanwrote: I'd love to make a cursor which also included the name of the person, but as far as I know there is no way to do that with a single query. That's probably true. That is, as far as I can tell, there's no way to do a join via the content provider interface, and permissions prevent us from accessing the contacts database directly via SQL calls. I really hope somebody can prove me wrong! I will be dealing with a somewhat similar situation later this week, when I attempt to join data from a ContentProvider and a SQLite database. Since what I want in the end is a Cursor, the approach I am trying is to use a custom CursorWrapper subclass. It will get handed the Cursor from the ContentProvider and will fold in the data from the SQLite database on demand as the relevant values are requested. Caching gets a mite tricky (gotta remember to flush the cache on requery(), for example), but I see no reason it won't work. -- Mark Murphy (a Commons Guy)http://commonsware.com _The Busy Coder's Guide to Android Development_ Version 1.4 Published! --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: Querys involving more than one table of Contatcs Content Provider
Dianne - thanks for the confirmation. I had spent a while banging my head on this issue, convinced that there ought to be an easy way if only I found the right ContentProvider magic. I can see that we will need to solve similar problems more than once, and I would love to stay in the world of Cursors, which means the CursorJoiner won't do it for us. I have the slightly hazy idea that we could write our own Cursor that took a pair of Cursors and a join expression, so as to do this in a general way. That would be handy in all sorts of ways. Do you think that would be practical ? Or is the absence of it in the SDK a clue that it is harder than it looks ? Thanks, Richard On Nov 26, 1:31 am, Dianne Hackborn [EMAIL PROTECTED] wrote: Correct, you can't directly do joins on the database. This is intentional, as the exact schema of the database can change over time, and a ContentProvider is intended to provide a more abstract mechanism for accessing it that can remain compatible as those changes occur. On Tue, Nov 25, 2008 at 7:03 AM, jarkman [EMAIL PROTECTED] wrote: I've been looking at a similar problem. Something like this: Cursor cursor = context.getContentResolver().query( Contacts.GroupMembership.CONTENT_URI, new String[] {Contacts.GroupMembership._ID,Contacts.GroupMembership.PERSON_ID, Contacts.GroupColumns.NAME}, Contacts.GroupMembership._ID = Contacts.Groups.GROUP_MY_CONTACTS, null, null); will get you the IDs of the people in the group. I'd love to make a cursor which also included the name of the person, but as far as I know there is no way to do that with a single query. That is, as far as I can tell, there's no way to do a join via the content provider interface, and permissions prevent us from accessing the contacts database directly via SQL calls. I really hope somebody can prove me wrong! Richard On Nov 24, 11:14 am, Huebi [EMAIL PROTECTED] wrote: I'd like to get a Cursor for all contacts in the My Contacts group. I could not figure out how to do this with the ContentProvider. As far as I understood the table structure, I need to use the GroupMembership table, the Groups table (to get the ID of the My Contacts group and the People table to actually retrieve the contact data. Has anyone successfully solved this task? Thanks! -- Dianne Hackborn Android framework engineer [EMAIL PROTECTED] Note: please don't send private questions to me, as I don't have time to provide private support. All such questions should be posted on public forums, where I and others can see and answer them. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: Querys involving more than one table of Contatcs Content Provider
On Wed, Nov 26, 2008 at 3:37 AM, jarkman [EMAIL PROTECTED] wrote: I have the slightly hazy idea that we could write our own Cursor that took a pair of Cursors and a join expression, so as to do this in a general way. That would be handy in all sorts of ways. Do you think that would be practical ? Or is the absence of it in the SDK a clue that it is harder than it looks ? Sure, Cursor is just an interface. For example: http://code.google.com/android/reference/android/database/MergeCursor.html -- Dianne Hackborn Android framework engineer [EMAIL PROTECTED] Note: please don't send private questions to me, as I don't have time to provide private support. All such questions should be posted on public forums, where I and others can see and answer them. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: Querys involving more than one table of Contatcs Content Provider
I've been looking at a similar problem. Something like this: Cursor cursor = context.getContentResolver().query( Contacts.GroupMembership.CONTENT_URI, new String[] {Contacts.GroupMembership._ID,Contacts.GroupMembership.PERSON_ID, Contacts.GroupColumns.NAME}, Contacts.GroupMembership._ID = Contacts.Groups.GROUP_MY_CONTACTS, null, null); will get you the IDs of the people in the group. I'd love to make a cursor which also included the name of the person, but as far as I know there is no way to do that with a single query. That is, as far as I can tell, there's no way to do a join via the content provider interface, and permissions prevent us from accessing the contacts database directly via SQL calls. I really hope somebody can prove me wrong! Richard On Nov 24, 11:14 am, Huebi [EMAIL PROTECTED] wrote: I'd like to get a Cursor for all contacts in the My Contacts group. I could not figure out how to do this with the ContentProvider. As far as I understood the table structure, I need to use the GroupMembership table, the Groups table (to get the ID of the My Contacts group and the People table to actually retrieve the contact data. Has anyone successfully solved this task? Thanks! --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: Querys involving more than one table of Contatcs Content Provider
jarkman wrote: I'd love to make a cursor which also included the name of the person, but as far as I know there is no way to do that with a single query. That's probably true. That is, as far as I can tell, there's no way to do a join via the content provider interface, and permissions prevent us from accessing the contacts database directly via SQL calls. I really hope somebody can prove me wrong! I will be dealing with a somewhat similar situation later this week, when I attempt to join data from a ContentProvider and a SQLite database. Since what I want in the end is a Cursor, the approach I am trying is to use a custom CursorWrapper subclass. It will get handed the Cursor from the ContentProvider and will fold in the data from the SQLite database on demand as the relevant values are requested. Caching gets a mite tricky (gotta remember to flush the cache on requery(), for example), but I see no reason it won't work. -- Mark Murphy (a Commons Guy) http://commonsware.com _The Busy Coder's Guide to Android Development_ Version 1.4 Published! --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---