简体   繁体   中英

RealmResults Query Returns Partial Results - Android

I am having a very strange behavior while querying data from my Realm table.

Example

I have an object called OrderItem defined like this:

public class OrderItem extends RealmObject{

   @PrimaryKey
   @Index
   private long id;

   //the rest of the fields here
   //then getters and setters as usual
}

The issue is quite unpredictable; because sometimes:

RealmResults<OrderItem> items = realm.where(OrderItem.class)
       .equalTo("order_id", order_id)
       .findAllSorted("id");

returns incomplete results - especially by 1 row;

This has been driving me nuts because I cannot exactly find out how it returns such partial results; doesn't matter how many rows I have in the said table!

NOTE

A while back, I was using a String type as the primary key in my table until I learned how bad an idea that was when trying to increment values; so I switched to long type which is fine; except now I get partial results from the query above!

I will truly appreciate your help on this! Any ideas, tips that could help me mitigate this issue.

Thanks in advance!

Eenvincible!

Have you cleared the database after switching primary key type? You can do this with:

Realm.deleteRealm();

I had some similar troubles with Realm database. Deleting and creating new database helped.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM