Lion789
Lion789

Reputation: 4482

How to add conflict replace for this table in sqlite?

I am having trouble adding on conflict replace for a Unique on two keys:

Here is the table:

private static final String CREATE_TABLE_USERS = "CREATE TABLE "
        + TABLE_USERS + "("
        + KEY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT,"
        + KEY_USER_ID + " TEXT NOT NULL,"
        + KEY_IS_TYPE + " INTEGER,"
        + KEY_DATE_ADDED + " LONG,"
        + "UNIQUE (" + KEY_USER_ID + ", " + KEY_IS_TYPE + ")"
        + ")";

How I insert them in Android SQLite Helper

SQLiteDatabase db = this.getWritableDatabase();
        ContentValues values = new ContentValues();
 return db.insert(TABLE_USERS, null, values);

I tried doing UNIQUE ON CONFLICT REPLACE but it does not work.

Upvotes: 0

Views: 1649

Answers (1)

CL.
CL.

Reputation: 180080

As shown in the documentation, the conflict clause must come after the column list:

...
UNIQUE (UserID, IsType) ON CONFLICT REPLACE

Upvotes: 4

Related Questions