This is the insert method that I use to insert some data into 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 an auto-increase field called booking_id . After inserting a new row, the value of this column increases by 1. Is it possible to return the booking_id of the row after the insert is completed in the above method without writing a separate selection request?
Or do I need to write a separate SQL Select query to return the booking_id from this newly inserted row?
source
share