Using the typical SQLiteDatabase object in Android’s API, what can I do to get the next AUTO_INCREMENT value of a particular column (ie. id) without affecting the value itself. Is there a method for that? Or what query should I execute to get that result. Keep in mind that SQLiteDatabase.query() returns a Cursor object, so I’m not too sure how to deal with that directly if I just want to get a value out of it.
Using the typical SQLiteDatabase object in Android’s API, what can I do to get
Share
You’re right. The first answer (still below) only works without an AUTOINCREMENT for id. With AUTOINCREMENT, the values are stored in a separate table and used for the increment. Here’s an example of finding the value:
See: http://www.sqlite.org/autoinc.html
First Answer:
You can query for the max of the _id column, such as:
This works for row ids that haven’t been specified as “INTEGER PRIMARY KEY AUTOINCREMENT” (all tables have a row id column).