我从服务器获取数据并将其存储在本地数据库中,即sqlite。它在sqlite中插入重复的值。
所以我的条件是:
我这样做了: -
SQLiteDatabase db = dbhelp.getWritableDatabase();
ContentValues values = new ContentValues();
String sqlq = "Select clid from client_detail";
Cursor cccs = db.rawQuery(sqlq, null);
if (cccs.getCount()== 0) {
values.put("clid", queryValues.get("clid"));
values.put("_id", queryValues.get("_id"));
values.put("client_id", queryValues.get("client_id"));
values.put("client_name", queryValues.get("client_name"));
values.put("client_mobile", queryValues.get("client_mobile"));
values.put("client_phone", queryValues.get("client_phone"));
values.put("client_email", queryValues.get("client_email"));
values.put("client_address", queryValues.get("client_address"));
db.insert("client_detail", null, values);
}else{
if (cccs.moveToFirst()) {
do{
Log.d("Client ID",""+cccs.getString(0));
clid.add(cccs.getString(0));
String temp = cccs.getString(0);
Log.d("Clid",temp);
if(temp.equals(queryValues.get("clid"))) //checking each id present in db
{
values.put("clid", queryValues.get("clid"));
values.put("lawyer_id", queryValues.get("_id"));
values.put("client_id", queryValues.get("client_id"));
values.put("client_name", queryValues.get("client_name"));
values.put("client_mobile", queryValues.get("client_mobile"));
values.put("client_phone", queryValues.get("client_phone"));
values.put("client_email", queryValues.get("client_email"));
values.put("client_address", queryValues.get("client_address"));
db.update("client_detail", values, null, null);
}
else{
values.put("clid", queryValues.get("clid"));
values.put("lawyer_id", queryValues.get("_id"));
values.put("client_id", queryValues.get("client_id"));
values.put("client_name", queryValues.get("client_name"));
values.put("client_mobile", queryValues.get("client_mobile"));
values.put("client_phone", queryValues.get("client_phone"));
values.put("client_email", queryValues.get("client_email"));
values.put("client_address", queryValues.get("client_address"));
db.insert("client_detail", null, values);
}
}while(cccs.moveToNext());
}
}