Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cant execute delete query properly using rawQuery

I want to deleting some rows of table info comparing another table type, my code goes as below. I am not getting any error or exception still I am unable to delete the data. Please suggest me

 String query = "delete from info where _id in " + 
                   "( select  a._id " +
                    " from info  a, type b," +
                    " where  a.t_id = b._id and b.type_name = 'Petrol'  )";

try{
     database.rawQuery(query,null);
}catch (Exception e){
    e.printStackTrace();
}
like image 269
Sharanabasu Angadi Avatar asked May 18 '13 12:05

Sharanabasu Angadi


2 Answers

The method SQLiteDatabase.rawQuery() is meant for querying --> SELECT statement.

To modify your data with raw SQL, you need to use SQLiteDatabase.execSQL().

like image 145
nicopico Avatar answered Nov 10 '22 19:11

nicopico


database.rawQuery(query,null).moveToFirst();

instead of

database.rawQuery(query,null);
like image 26
Ajeeth Kumar Avatar answered Nov 10 '22 20:11

Ajeeth Kumar