mercredi 2 septembre 2015

deleting records from sqlite on the basis of date in android

I want to delete some records from android's database where two conditions are fulfilled. 1. there's a column with the name as sync_status, it should have a value 'C' and 2. there's column which has date.

Now I want to delete only those rows where sync_status is = 'c' and date is less than device's current date. I'm having problem in comparing the device's current date with the date stored in the database and my function deletes all the records.

public int RemoveSyncData(){

      DBHelper = new DatabaseHelper(context); 
      DateFormat dateFormat = new SimpleDateFormat("MM-dd-yyyy ");
      Calendar calObj = Calendar.getInstance();
      String currentDate = dateFormat.format(calObj.getTime());
      Log.e("current date",currentDate);

      int rows = db.delete(DATABASE_TABLE_DAILY_ATTENDANCE, KEY_ATTENDANCE_SYN_STATUS + "= ? and " + KEY_ATTENDANCE_DATE_ONLY + " != '" + currentDate + "'", new String[] {"C"});

      db.close();
      return rows;
}

Aucun commentaire:

Enregistrer un commentaire