1

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?

The 29th Saltshaker
  • 671
  • 1
  • 6
  • 16

1 Answers1

1

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.

Jeffrey Blattman
  • 22,176
  • 9
  • 79
  • 134