John McKenzie
John McKenzie

Reputation: 420

ActiveAndroid Update and Delete from table

Hi guys so I'm trying to test how to use databases in android as part of one of my classes, but I'm pretty new to both so most help I found online has gone a bit over my head.

I was wondering how exactly do I update, and delete from the table. Currently I have:

    wk item = new wk();
            item.name = "okay1";
            item.save();

And that adds an item fine.

and in my database it has

public class wk extends Model {
    Table(name = "ToDoItems")
    @Column(name = "Name")

But I try to run

new Delete().from(wk.class).where("Name = ?",2).execute();

Which I'm assuming deletes the value at 2 in the database of Name, but instead it seems to do nothing? I have tried

new Delete().from(wk.class).execute();

Which does definitely delete my table so I know it can delete, but I just want to delete one value.

Pretty much I want to be able to delete that okay1 value.

Upvotes: 1

Views: 8464

Answers (3)

Shashwat Gupta
Shashwat Gupta

Reputation: 872

if your condition return single value

new Delete().from(modelclassname.class).where("OnBasisof=?",value).executesingle();

if your condition return multiple value

new Delete().from(modelclassname.class).where("OnBasisof=?",value).execute();

Upvotes: 0

John McKenzie
John McKenzie

Reputation: 420

Okay I found the answer I had for deleting which is

new Delete().from(wk.class).where("Name = ?","okay1").execute();

And works perfect for me now.

Upvotes: 9

Fred B.
Fred B.

Reputation: 1721

As explained in the documentation of ActiveAndroid, you can as well delete your object statically :

public static void delete(MyClass obj){
    obj.delete();
}

It can be useful, especially if you are using a DAO design pattern.

Upvotes: 4

Related Questions