-1

I am trying to remove certain rows of a table in Android. I tried running directly through the SQL command "execSQL" and "rawQuery". Right now I'm using "db.delete" where I step in the argument "where" the rows that I want to remove.

This is the code:

String where = DBTables.TActivities.ID + " NOT IN ( " +
                " SELECT " + DBTables.TInscripcionesActividades.ID_ACTIVIDAD + " FROM " +DBTables.TInscripcionesActividades.TABLE_NAME + " );";

db.beginTransaction();
db.delete(DBTables.TActivities.TABLE_NAME, where, null);
db.endTransaction();

I tested the sql petition in a BBDD browser and it works fine.

I want to delete all records of the table "TActividades" except the activities whose IDs are in the "TInscripcionesActividades" table.

Any ideas?? Thanks in advance!

2 Answers2

3

You need to call setTransactionSuccessful() before endTransaction() for the changes to take effect.

laalto
  • 150,114
  • 66
  • 286
  • 303
2
String where = DBTables.TActivities.ID + " NOT IN ( " +
                " SELECT " + DBTables.TInscripcionesActividades.ID_ACTIVIDAD + " FROM " +DBTables.TInscripcionesActividades.TABLE_NAME + " );";

db.beginTransaction();
db.delete(DBTables.TActivities.TABLE_NAME, where, null);
db.setTransactionSuccessful();
db.endTransaction();
SRB Bans
  • 3,096
  • 1
  • 10
  • 21