lundi 31 août 2015

How to insert into a junction table using a content provider/content values/AsyncQueryHandler

I'm trying to insert into a junction table in Android. I already set up a content provider and have been using an AsyncQueryHandler to perform a lot of my operations in classes that don't require loaders. However, I need to insert into a junction table, and I'm at a loss for how to handle querying the related tables in order to receive the _ID values to place into the junction tables via a content provider/queryhandler.

For example, from this post's answer: Automatically Create Insert Statements to Fill Junction Table in a Pre-Created DB

 insert into Name_Category values(
  (select _id from Categories where category='CAT1'),
  (select _id from Names where name='NAME1'));

(Edit) Here is an additional example: Insert into a junction table in SQLite

INSERT INTO ListsAndPlayers (ListsAndPlayersID, ListID, PlayerID)
VALUES (42,
    (SELECT ListID FROM Lists WHERE ListName = 'Los Angeles Dodgers'),
    (SELECT PlayerID FROM Players WHERE PlayerName = 'Clayton Kershaw'));

I have a very similar need in my application, and couldn't find any documentation on handling this with AsyncQueryHandlers or ContentProviders/ContentValues. What would the equivalent of this be using one of those?

Does anyone have suggestions for how they have handled this?

Thanks!

Aucun commentaire:

Enregistrer un commentaire