I am using Android / Java and SQLite3 / SQLiteOpenHelper, with the Cursors and ContentValues.
I have a timestamp field in my table. I want to ensure that if someone is adding a new row, the row is not added if the timestamp is already occupied (so I do not want more than one value per timestamp).
Can this be enforced efficiently? Or do I have to perform a select statement every single time I perform an insertion to check first?
Add a UNIQUE
qualifier on the timestamp field. You can then choose the behavior you want by calling inserWithOnConflict()
and passing CONFLICT_FAIL
as the conflict algorithm argument.