Auto increment of a key id
nikiJava opened this issue · comments
Guys, how to implement auto increment of a key (id) when put() operation is used if that key is INTEGER?
I found the solution - it works only with wrappers of primitive types (Integer but not int). Am I making a mistake or is it working in this way only?
Anyway you should pass to SqlLiteOpenHelper null
to make auto increment.
If you decided not to use null
as mark that value was not inserted yet, you can apply some another value of int
for this purpose and after then map it to null
in custom put resolver.
public ContentValues mapToContentValues(@NonNull Tweet object) {
ContentValues contentValues = new ContentValues(3);
contentValues.put("_id", object.id != -1 ? object.id : null);
Closing. Feel free to comment or reopen