1

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:

  1. SQLiteDatabase.query first and apply an update if there is one
  2. Always use SQLiteDatabase.replace, in case the UNIQUE constraint fail, sqlite will replace the record.

    Which approach is better? Are there other suggestions? Thanks

1 Answer 1

1

Since this seems to be a commom issue (which I faced recently too) I found this post which might be helpful.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.