user1876202
user1876202

Reputation: 361

Android SQLite catch error using execSQL

I have a method that runs a INSERT SQL statment that are got from external soruces and not from the android device. The incoming statments can cause duplicate records and I want the android device to ignore the sql statments if they cause duplicates. The method is:

    ourDatabase.execSQL(sql)

The table its inserting the data into has the following column that prevents duplicates

    KEY_CONCATA + " TEXT PRIMARY KEY , " +

Should this be unique and not primary key?

The system at the moment recognizes its causing a duplicate and ends the program, I want it to catch the error and stop it being inserted into the database if its a duplicate.

Thanks!

Upvotes: 0

Views: 803

Answers (1)

Hoan Nguyen
Hoan Nguyen

Reputation: 18151

Declare KEY_CONCATA TEXT NOT NULL UNIQUE and when insert use insertWithOnConflict with SQLiteDatabase.CONFLICT_IGNORE flag

Upvotes: 1

Related Questions