Answer the question
In order to leave comments, you need to log in
How to remove duplicate values in SQLite?
How not to skip duplicate values to a record??
1) database
public class DBHelper extends SQLiteOpenHelper{
public static final int DATABASE_VERSION = 1;
public static final String DATABASE_NAME = "contactDb";
public static final String TABLE_CONTACTS = "contacts";
public static final String KEY_ID = "_id";
public static final String KEY_NAME = "name";
public static final String KEY_MAIL = "mail";
public DBHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("create table " + TABLE_CONTACTS + "(" + KEY_ID
+ " integer primary key," + KEY_NAME + " text," + KEY_MAIL + " text" + ")");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("drop table if exists " + TABLE_CONTACTS);
onCreate(db);
}
}
//////////////////////////////////
////////////// /////////
////////////////////////////////// 2) Adding to the
String
database
value3 = adapter.getItem(position).title;
int value2 = adapter.getItem(position).price;
SQLiteDatabase database = dbHelper.getWritableDatabase();
contentValues contentValues = new ContentValues();
switch (index) {
case 0:
contentValues. put(DBHelper.KEY_NAME, value3);
contentValues.put(DBHelper.KEY_MAIL, value2);
database.insertWithOnConflict(DBHelper.TABLE_CONTACTS, null, contentValues, SQLiteDatabase.CONFLICT_REPLACE);
Toast.makeText(getApplicationContext(), "Action 2 for " + value3 +"price"+ value2, Toast.LENGTH_SHORT ).show();
break;
Answer the question
In order to leave comments, you need to log in
db.execSQL("create table " + TABLE_IZBRANNOE + "(" + KEY_ID
+ " integer primary key on conflict replace," + KEY_NAME + " text unique on conflict ignore," + KEY_PRICE + " text" + ")");
Make a unique index
https://www.sqlite.org/lang_createindex.htmlCREATE UNIQUE INDEX .... ON .... (mail)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question