-1

I want to delete the all rows by dates. In the table I have the rows with this format:2014-01-01. Now, I want to delete the all rows by date range. I have created this method, but I believe there is a syntax error:

 public void deleteAllEntrate_e_uscite(View v) {
    SQLiteDatabase db = mHelper.getWritableDatabase();
      db.delete(MyTable.TABLE_NAME, MyTable.DATA + "BETWEEN" +dateAndTime+ "AND" +dateAndTime1, null);
    db.close();
    finish(); 

}
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
JJkk
  • 133
  • 1
  • 9

3 Answers3

1

When concatenating you are not leaving a space between the elements.

db.delete(MyTable.TABLE_NAME, MyTable.DATA + " BETWEEN " +dateAndTime+ " AND " +dateAndTime1, null);
0

You need to separate your keywords:

MyTable.DATA + "BETWEEN" +dateAndTime+ "AND" +dateAndTime1

you need spaces AND you need apostrophes, since your dates are strings:

MyTable.DATA + " BETWEEN '" +dateAndTime+ "' AND '" +dateAndTime1 +"'"
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
0

Since you are comparing date(not column of type int),you have to use apostrophes.So the query will be like this.

db.delete(MyTable.TABLE_NAME, MyTable.DATA + "BETWEEN '" +dateAndTime+ "' AND '" +dateAndTime1+"'", null);

Also add one white space between 'BETWEEN' & the DATE PARAMETER.Other wise you will get SQLiteException. One suggestion too,before executing every query please ensure that the db connection(here 'db') is not null.

Jinosh P
  • 341
  • 2
  • 8