0

I have an already functioning app running on iOS whose database uses a composite primary key. For discussions sake, lets say "CID" and "RID" make up that composite pk, resulting in something that looks like:

CID-RID
F6uuDTEU1c-1
F6uuDTEU1c-2
F6uuDTEU1c-3

However, there are conditions under which the CID column is altered, resetting the RID column. For example:

CID-RID
...
F6uuDTEU1c-4
F6uuDTEU1c-5
WQq6JnyrDI-1
WQq6JnyrDI-2
WQq6JnyrDI-3
...etc

These databases are to be shared cross-platform (ios - android) and going back and editing the current ios structure is not an option. What issues am I going to run into not having an _id column as my pk running on Android?

I found this here on SO - which seems to state that the db itself does not have to have the _id column, only that ...

"The result set for the cursor must contain _id, not the cursor itself."

... but I could be reading this all wrong. Any input/help is much appreciated.

PS: I already looked at a few (what I thought were) similar questions here, here, and here.

Community
  • 1
  • 1
Warblr
  • 1,188
  • 1
  • 13
  • 27

1 Answers1

6

You are free to have any database schema you want. Android doesn't impose any additional restrictrions there.

Only if you use a CursorAdapter, then the Cursor needs an _id column. Any app can be written without using CursorAdapter, it's just there to provide some convenience. sqlite tables always have a ROWID column that aliases to the INTEGER PRIMARY KEY column if the table has one. You can always select it as the _id, e.g. SELECT rowid AS _id ... if needed.

laalto
  • 150,114
  • 66
  • 286
  • 303
  • Thanks so much for your response, @laalto! Interesting, so even if I don't create rowid and set a totally different column (or columns in this case) as the primary key, rowid will exist? Also, how difficult is it to manage the db without the convenience of the cursoradapter? Do you know of any tutorials explaining how this works? I was very excited to find the simplicity they provide. – Warblr Jul 29 '14 at 05:23
  • 1
    Yes, all rows have a rowid and it will be same as the pk if the pk is integer. You'd use a cursoradapter for mapping cursor data to an adapter view such as list view. It's just slightly more code if you write your own custom adapter that does the mapping. – laalto Jul 29 '14 at 05:50