I want to synchronize the android application with server. In Server i have maintained last update date through trigger as it uses SQL server but my android application uses Realm so how can i set current date time in a field whenever any row is inserted or updated. Any suggestion would be highly appreciated.
5
-
do you want to insert it in separate column ? if it is then you can set currentTimeStamp value in object of Class and then insert– Ashish AgrawalCommented Sep 23, 2015 at 9:22
-
1Yes i can but it will be very risky - as i have to do it for every insert and update manually.– Syed HassanCommented Sep 23, 2015 at 9:29
-
can you use update query at last– Ashish AgrawalCommented Sep 23, 2015 at 9:30
-
I am using realm. i cannot get your suggestion.– Syed HassanCommented Sep 23, 2015 at 9:51
-
please see my answer if it can help– Ashish AgrawalCommented Sep 23, 2015 at 9:53
Add a comment
|
2 Answers
use this
realm.beginTransaction();
RealmResults<ModelClass> hallos = realm.where(ModelClass.class).equalTo('name', 'hello').findAll();
for (ModelClass object : hallos) {
object.setTimeStamp(timestamp);
}
realm.commitTransaction();
-
6I want to automate this system because i don't want to do it every time i insert/update any row. Commented Sep 28, 2015 at 6:45