Reputation: 594
I have a table like this
db.execSQL("CREATE TABLE " + TABLE_NAME + " ("
+ _ID + " INTEGER PRIMARY KEY,"
+ URL + " TEXT UNIQUE,"
+ SomeInfo + " TEXT,"
+ OtherInfo + " INTEGER"
+ ");");
So there is only one record for each URL value. When the user visit a URL, I need neither insert a new row, or update an existing row if URL is presented I could think of 2 ways:
SQLiteDatabase.query
first and apply an update if there is oneAlways use SQLiteDatabase.replace
, in case the UNIQUE constraint fail, sqlite will replace the record.
Which approach is better? Are there other suggestions? Thanks
Upvotes: 1
Views: 2180