I call insertWithOnConflict using SQLiteDatabase.CONFLICT_IGNORE. However, if a conflict occurs, returns "-1" instead of the identifier of the existing string. How to fix it?
Creating a table:
EDIT:
String CREATE_CATEGORY_TABLE = "CREATE TABLE "+TABLE_CATEGORY+"(" + BaseColumns._ID+" INTEGER PRIMARY KEY AUTOINCREMENT, "+ KEY_CATEGORY_NAME+" TEXT UNIQUE" + ")"; db.execSQL(CREATE_CATEGORY_TABLE);
Insert instruction:
ContentValues values = new ContentValues(); values.put(KEY_CATEGORY_NAME, name); int catID = (int) db.insertWithOnConflict(TABLE_CATEGORY, null, values, SQLiteDatabase.CONFLICT_IGNORE);
android insert sqlite
meeeee
source share