jeudi 17 septembre 2015

Delete Rows from a table linked in sqlite

I have problems deleting the rows from a table.

I have 2 tables with the next definition:

private static final String DATABASE_TABLEELEMENTS = "elements";
    public static final String KEY_ROWELEMENTID = "_id";
    public static final String KEY_STUDYID = "idstudy";
    public static final String KEY_ELEMENTCODE = "code_element";
    public static final String KEY_ELEMENTNAME = "description_element";


private static final String DATABASE_TABLETIME = "times";
    public static final String KEY_ROWTIME = "_id";
    public static final String KEY_ELEMENTID = "idelement";
    public static final String KEY_HOURDATE = "hour_date";
    public static final String KEY_OBSERVEDYTIME = "observedtime";
    public static final String KEY_OBSERVEDACTIVITY = "observedactivity";

both tables are related: elements._id = times.idelement

I want to delete all rows in table "times" which has the "idstudy" from table "elements" that the user has selected:

for this I create the next function:

            public void ResetDataStudies(String selectedid) {
            // TODO Auto-generated method stub

            String querytimes = "DELETE FROM "
                    + "times"
                    + " WHERE "
                    + "times.idelement"
                    + " IN "
                    + "(SELECT "
                    + "elements._id"
                    + " FROM "
                    + "elements"
                    + " WHERE "
                    + "elements.idstudy = ?)";
            ourDatabase.rawQuery(querytimes, new String[] { selectedid });


        } 

I don't receive an specific error but after execute it the data has not been deleted.

Any idea?

Aucun commentaire:

Enregistrer un commentaire