>From the documentation for CursorJoiner the following line -

"This joiner only supports the case where the tuple of key column
values is unique."

- worries me in that the key column AccountBook.Spend.CATEGORY_ID is
not unique (it can't be as it is the link to the parent table).

I am not sure I am right about this and will need to spend some time
with some test data.  But if I am then CursorJoiner does not suitable
choice to implement one-to-many joins, but only one-to-one optional
joins.

As I said I am not sure about this and am going to do some testing.
Will let you know what I find.

--
RichardC


On Oct 16, 12:42 pm, RichardC <[email protected]> wrote:
> I do the join in the content provider using a different Uri for the
> joined view.  For example you could use
>
> content://com.example.my_provider/spend_with_category
>
> as the Uri and do the join when you create the cursor.
>
> --
> RichardC
>
> On Oct 16, 12:34 pm, Victor Lin <[email protected]> wrote:
>
> > But how about ContentProvider? I didn't query database directly, I
> > used ContentProvider.
>
> > On 10月16日, 下午6時39分, RichardC <[email protected]> wrote:
>
> > > You can use a JOIN clause in SQLiteQueryBuilder.setTables
>
> > >http://developer.android.com/reference/android/database/sqlite/SQLite...
>
> > > --
> > > RichardC
>
> > > On Oct 16, 10:50 am, Victor Lin <[email protected]> wrote:
>
> > > > Hi, I have two tables:
>
> > > > Category(_id, name)
> > > > Spend(_id, spend, category_id)
>
> > > > I want to join these two tables. I tried to use CursorJoiner:
>
> > > >         Cursor spendCursor = managedQuery(
> > > >                 AccountBook.Spend.CONTENT_URI,
> > > >                 new String[] { AccountBook.Spend._ID,
> > > > AccountBook.Spend.SPEND, AccountBook.Spend.CATEGORY_ID },
> > > >                 null, null, AccountBook.Spend.CATEGORY_ID
> > > >         );
>
> > > >         Cursor categoryCursor = managedQuery(
> > > >                 AccountBook.Category.CONTENT_URI,
> > > >                 new String[] { AccountBook.Category._ID,
> > > > AccountBook.Category.NAME },
> > > >                 null, null, AccountBook.Category._ID
> > > >         );
>
> > > >         CursorJoiner joiner = new CursorJoiner(
> > > >                 spendCursor, new String[] { 
> > > > AccountBook.Spend.CATEGORY_ID },
> > > >                 categoryCursor, new String[] { AccountBook.Category._ID 
> > > > }
> > > >         );
>
> > > > With following data:
>
> > > > Spend's category_id: 1, 1, 1, 1, 2
> > > > Category's _id: 1, 2, 3
>
> > > > I got following results of CursorJoiner :
>
> > > > BOTH
> > > > LEFT
> > > > LEFT
> > > > LEFT
> > > > BOTH
> > > > RIGHT
>
> > > > That's strange, it seems the behavior of CursorJoiner is not like the
> > > > behavior of join of usual database. What I want is, list all spends in
> > > > list with its category's name.
>
> > > > For example:
>
> > > > Spends (_id, spends, category_id) :
> > > > 1, 999, 1
> > > > 2, 55, 2
> > > > 3, 30, 2
> > > > 4,, 60, 3
>
> > > > Categories (_id, name):
> > > > 1, food
> > > > 2. tips
> > > > 3. 3C products
>
> > > > And I want the list looks like:
>
> > > > (spend.spend, category.name)
> > > > 999, food
> > > > 55, tips
> > > > 30, tips
> > > > 60, 3C products
>
> > > > How can I achieve this with Android?
>
> > > > Thanks.
> > > > Victor Lin.
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to