This is the insert method I am using to insert some data into the db:
public long insertBooking(String userId,int roomId,Timestamp checkInTime, Timestamp checkOutTime){
final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
ContentValues contentValues=new ContentValues();
contentValues.put(USER_ID, userId);
contentValues.put(ROOM_ID, roomId);
contentValues.put(CHECK_IN, dateFormat.format(checkInTime));
contentValues.put(CHECK_OUT, dateFormat.format(checkOutTime));
return database.insert(MRM_BOOKING_DETAILS_TABLE, null, contentValues);
}
The MRM_BOOKING_DETAILS table has got an auto-increment field called booking_id. After inserting a new row, the value of this column is incremented by 1. Is it possible to return the booking_id of the row once the insertion is completed in the above method itself without writing a separate select query?
Or, do I have to write a separate SQL Select query to return that booking_id of that newly inserted row?
long insertId = database.insert(MRM_BOOKING_DETAILS_TABLE, null, contentValues);
this line itself returns the booking_id of the inserted row…