0

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!

2
  • You can have a TEXT PRIMARY KEY and a primary key is unique by default... What is the error? Commented Apr 11, 2013 at 18:52
  • column concata is not unique (code 19) Commented Apr 11, 2013 at 18:53

1 Answer 1

1

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

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

5 Comments

Im not sure if this will work, because the incoming is a SQL statment e.g INSERT INTO database_table WHERE..... im guessing such a input would not work with insertWithOnConflict?
Try KEY_CONCATA TEXT NOT NULL UNIQUE ON CONFLICT IGNORE
Or KEY_CONCATA + " TEXT PRIMARY KEY ON CONFLICT IGNORE, " +
@Sam I think your statement requires NOT NULL because sqlite allows PRIMARY_KEY field to be null
KEY_CONCATA + " TEXT NOT NULL UNIQUE ON CONFLICT IGNORE , " + is what worked fo rme

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.