2

Normally when I do a select query in SQLite in Android I will use a Cursor object from SQLiteDatabase.query() and then iterate over that cursor, pull out the column data, and use that data as the arguments for the constructors of objects.

However what if I have a more complicated relationship for my objects? For example if I have an object that contains lists of objects, and those objects contain lists of objects as well, and maybe some of them have multiple key combinations.

For example I can't iterate over the Cursor and then call query() on every single iteration, and then on every iteration on that level, etc, which is basically calling a query per query per query, etc.

Is the accepted approach to use a join query and then try to construct it from one giant dataset?

KaliMa
  • 1,970
  • 6
  • 26
  • 51
  • See [What is the n+1 selects issue?](http://stackoverflow.com/questions/97197/what-is-the-n1-selects-issue) – CL. Sep 28 '16 at 08:17
  • @CL So they do make a giant join query for everything so you don't have to do more than 1 select? – KaliMa Sep 28 '16 at 13:40
  • It would be possible to use two queries: [How do I parse efficiently one to many relation in model objects?](http://stackoverflow.com/q/19756757/11654) – CL. Sep 28 '16 at 14:45
  • @CL. I am asking a slightly different question than that. In my case the nested objects may have multiple keys at the same time. For example a car with multiple wheels, but maybe the wheels also have traits that depend on the unique combination of car and wheel type (or something) So it could be a 1 + N(1 + (1 + N ... type problem – KaliMa Sep 28 '16 at 17:53
  • The point being that I can call a separate select query every single time I need to add another object to a given object's list (no matter how deep the chain) but this is inefficient – KaliMa Sep 28 '16 at 17:55

0 Answers0