MDP
MDP

Reputation: 4287

How to retrieve last _ID from SQLite

I have a "logic" problem when making "inserts" on the SQLite database of my app.

These are my tables.enter image description here How should I manage the "need" of retrieving contact_id and photos_id in order to make the insert into the table contact_photo?

I know that I can get the last _id generated by SQLite with SELECT seq from sqlite_sequence where ..., but this doesn't seem a "professional" solution.

Is there a better way to achieve my goal?

Thank you in advance

Upvotes: 1

Views: 66

Answers (1)

Behnam Eskandari
Behnam Eskandari

Reputation: 1041

have a look to this document

long insertOrThrow (String table, 
                String nullColumnHack, 
                ContentValues values)

will returns row ID of the newly inserted row, or -1 if an error occurred

Upvotes: 1

Related Questions