I have an application and I am pretty confused to why insertWithOnConflict returns the wrong value continuously.
My code looks like this:
I create the table:
StringBuffer sql = new StringBuffer("CREATE TABLE IF NOT EXISTS " + TABLE_NAME);
sql.append("(_id INTEGER PRIMARY KEY, name VARCHAR CONSTRAINT uk_name UNIQUE, modifiable BOOLEAN DEFAULT true); ");
I think try to insert a duplicate value into the table:
ContentValues values = new ContentValues();
values.put("name", name);
long row = gDatabase.insertWithOnConflict(TABLE_NAME, null, values, SQLiteDatabase.CONFLICT_IGNORE);
When I call insertWithOnConflict on a name that would violate the UNIQUE constraint I get back a 0. The correct value of the primary key is 5. I looked and the api says it returns -1 when there is an error. Well what does it mean when it returns a 0 (The wrong _id) the whole time.