I am working on a billing android app. I need to prevent duplication only if all the rows in table repeat again.
I had add a roll back method
rows = db.insertWithOnConflict("output_to_cloud4", null, cv, SQLiteDatabase.CONFLICT_REPLACE);
But still inserting duplicate details
-Here I am sharing my inserting method
void Insert_OutputDetails_withTransation() {
long rows = 0;
db = openOrCreateDatabase("Student.db",OPEN_READWRITE, null);
ContentValues cv = new ContentValues();
db.beginTransaction();
try {
for (int i = 0; i < myMap.size(); i++) {
float check_not_zeroValue = Float.parseFloat(myMap.get(PosUtils.PRODUCT_CODE.get(i)));
if (!(check_not_zeroValue == 0.0f)) {
try {
int time = (int) (System.currentTimeMillis());
Timestamp tsTemp = new Timestamp(time);
String ts = tsTemp.toString();
Double round_amount = Double.valueOf(Rounded_Total_price_with_tax) - Double.valueOf(Total_price_with_tax);
cv.put("BILLNO", (LAST_BILL_NUMBER));
cv.put("BILLPREFIX", SALES_MAN_BILLPREFIX);
cv.put("BILLDATE", Date);
cv.put("saleman_code", SALES_MAN_CODE);
cv.put("DLYVEHICLE", SALES_MAN_DLYVANNO);
//"CUSTOMERCODE","PRODUCTCODE","QTY","RATE","GROSS",
cv.put("CUSTOMERCODE", CUSTOMERS_CODE_LIST.get(CUSTOMER_POSITION));
cv.put("PRODUCTCODE", PRODUCT_CODE.get(i));
cv.put("QTY", myMap.get(PosUtils.PRODUCT_CODE.get(i)));
cv.put("RATE", PRODUCT_RATE.get(i));
cv.put("GROSS", new DecimalFormat("0.00").format(item_price));
//"CGST","CGSTAMT","SGSTP","SGSTAMT","CESSP",
cv.put("CGST", PRODUCT_CGSTP.get(i));
cv.put("CGSTAMT", new DecimalFormat("0.00").format(amount_cgst));
cv.put("SGSTP", PRODUCT_SGSTP.get(i));
cv.put("SGSTAMT", new DecimalFormat("0.00").format(amount_sgst));
cv.put("CESSP", PRODUCT_CESSP.get(i));
//"CESSAMT","SCESSP","SCCAMT","ROUND","BTOTAL","
cv.put("CESSAMT", new DecimalFormat("0.00").format(amount_cseep));
cv.put("SCESSP", PRODUCT_SCESSP.get(i));
cv.put("SCCAMT", new DecimalFormat("0.00").format(amount_scessp));
cv.put("BTOTAL", new DecimalFormat("0.00").format(Rounded_Total_price_with_tax));
cv.put("ROUND", new DecimalFormat("0.00").format(round_amount));
cv.put("BILL_STATUS", "1");
rows = db.insertWithOnConflict("output_to_cloud4", null, cv, SQLiteDatabase.CONFLICT_REPLACE);
} catch (Exception in) {
in.getMessage();
}
}
}
db.setTransactionSuccessful();
} catch (Exception e) {
e.getMessage();
} finally {
db.endTransaction();
}
}
My database Formate
db.execSQL("CREATE TABLE IF NOT EXISTS output_to_cloud3(" +
"BILLNO TEXT,BILLPREFIX TEXT,BILLDATE TEXT,saleman_code TEXT,DLYVEHICLE TEXT," +
"CUSTOMERCODE TEXT,PRODUCTCODE TEXT,QTY TEXT,RATE TEXT,GROSS TEXT," +
"CGST TEXT,CGSTAMT TEXT,SGSTP TEXT,SGSTAMT TEXT,CESSP TEXT," +
"CESSAMT TEXT,SCESSP TEXT,SCCAMT TEXT,ROUND TEXT,BTOTAL TEXT,BILL_STATUS TEXT,TIME_IN TEXT)");
If anybody face this problem before help me.....

