Sugar ORM on Android: updating a saved object in SQLite

I am new to application development using SQLite and Sugar ORM on Android and tried to read the Sugar ORM documentation but found nothing how to update a saved object in SQLite. Can I save an object after changing its properties? sort of:

Customer myCustomer = (Customer.find(Customer.class, "id = ?", id)).get(0);
myCustomer.setName("new name");
myCustomer.setAddress("new Address");
myCustomer.save(); // is this okay for updating the object?

the save () method will not create another new object, leaving the old record intact, right?

+5
source share
4 answers

He will renew your essence. Sugar ORM overwrites an existing name, such as Name, and updates it with the "new name" after calling save ().

+3
source

Your code should update the line without problems.

- Update Entity:

Book book = Book.findById(Book.class, 1);
book.title = "updated title here"; // modify the values
book.edition = "3rd edition";
book.save(); // updates the previous entry with new values.
+5

.

;

Object object= Object.findById(Object.class, ID);

:

object.setAttr("new value");

, , save;

object.save();

, , update(), ;

;

Object object= new Object();
object.setAttr("some data");

, , ;

object.setID(ID);

,

object.update();
0

Save Object , . , :

Object.save();

, :

column1       column2
1             1

column1 , 2, :

Object.save();

column1       column2
2             NULL

Object.update();

column1       column2
2             1

.setId(), , , , , , . . , :

@Unique
String MyID

, :

@MultiUnique("MyFirstID,MySecondID")
public class MyClass extends SugarRecord {...

.

0

All Articles