I use ObjectBox to save my data, and I encouter the DbException(-30797), please see bellow for detail information. I can't find any thread or information for code -30797, I don't know how should I do if there is an error with code. Does the ObjectBox has any error code map for us to locate the problem?
ext.objectboxVersion = '2.2.0'
always
just put the Entity into database
public void put(VitalData... datas) {
mBox.put(datas);
}
System.err: io.objectbox.exception.DbException: Could not put (-30797) (error code -30797)
at io.objectbox.Cursor.collect313311(Native Method)
at com.vivalnk.sdk.demo.vital.data.VitalDataCursor.put(VitalDataCursor.java:70)
at com.vivalnk.sdk.demo.vital.data.VitalDataCursor.put(VitalDataCursor.java:16)
at io.objectbox.Box.put(Box.java:385)
```java
public class DatabaseManager {
private BoxStore mBoxStore;
private Context mContext;
private static class SingletonHolder {
private static final DatabaseManager INSTANCE = new DatabaseManager();
}
private DatabaseManager(){
}
public static DatabaseManager getInstance() {
return SingletonHolder.INSTANCE;
}
public void init(Context context) {
this.mContext = context.getApplicationContext();
File dataDir = FileUtils.getDataDir(context);
String sdkBaseDir = dataDir.getAbsolutePath() + "/vitalsdk";
this.mBoxStore = MyObjectBox.builder().directory(new File(sdkBaseDir)).androidContext(context)
.build();
}
public BoxStore getBoxStore() {
return mBoxStore;
}
public
return mBoxStore.boxFor(t);
}
}
```java
public class VitalDataDAO {
private Box<VitalData> mBox;
private static volatile VitalDataDAO sVitalDataDAO;
public static VitalDataDAO getInstance() {
if (sVitalDataDAO == null) {
synchronized (VitalDataDAO.class) {
if (sVitalDataDAO == null) {
sVitalDataDAO = new VitalDataDAO();
}
}
}
return sVitalDataDAO;
}
private VitalDataDAO() {
mBox = DatabaseManager.getInstance().getBox(VitalData.class);
}
public void put(VitalData... datas) {
mBox.put(datas);
}
public List<VitalData> get(long ... ids) {
return mBox.get(ids);
}
public List<VitalData> getAll() {
return mBox.getAll();
}
public Query<VitalData> getHistoryData(long startTime, long endTime) {
Query<VitalData> query = mBox.query()
.between(VitalData_.date, startTime, endTime)
.order(VitalData_.date)
.build();
return query;
}
//TODO need implementation
public void queryByDate(long date) {
}
}
@Entity
public class VitalData {
@Id
public long id;
public String mac;
public String sn;
public int frequency;
public int magnification;
@Index
public long date;
public boolean leadOn;
public String rri;
public String acc;
public String ecg;
// public int crc16;
// public byte[] rawBytes;
// public boolean success;
// @Transient
// public byte[] crcBytes;
// @Transient
// public ArrayList<Integer> lackFrame;
@Transient
static Gson gson = new Gson();
public VitalData() {
}
public VitalData(VitalData vitalData) {
this.id = vitalData.id;
this.mac = vitalData.mac;
this.sn = vitalData.sn;
this.frequency = vitalData.frequency;
this.magnification = vitalData.magnification;
this.date = vitalData.date;
this.leadOn = vitalData.leadOn;
this.rri = vitalData.rri;
this.acc = vitalData.acc;
this.ecg = vitalData.ecg;
}
public VitalData(Device device, SampleData sampleData) {
setValue(device, sampleData, 250, 3776);
}
public VitalData(Device device, SampleData sampleData, int frequency, int magnification) {
setValue(device, sampleData, frequency, magnification);
}
public void setValue(Device device, SampleData sampleData, int frequency, int magnification) {
this.date = sampleData.date;
this.leadOn = sampleData.leadOn;
this.rri = gson.toJson(sampleData.rri);
this.acc = gson.toJson(sampleData.acc);
this.ecg = gson.toJson(sampleData.ecg);
// this.crc16 = sampleData.crc16;
// this.rawBytes = sampleData.rawBytes;
// this.success = sampleData.success;
// this.crcBytes = sampleData.crcBytes;
// this.lackFrame = sampleData.lackFrame;
this.mac = device.getId();
this.sn = device.getName();
this.frequency = frequency;
this.magnification = magnification;
}
public int[] parseECG() {
return gson.fromJson(ecg, int[].class);
}
public void setEcg(int[] ecgArray) {
ecg = gson.toJson(ecgArray);
}
public Motion[] parseACC() {
return gson.fromJson(acc, Motion[].class);
}
public int[] parseRRI() {
return gson.fromJson(rri, int[].class);
}
@Override
public String toString() {
return "VitalData{" +
"id=" + id +
", date=" + date +
", leadOn=" + leadOn +
", rri='" + rri + '\'' +
", acc='" + acc + '\'' +
", ecg='" + ecg + '\'' +
", gson=" + gson +
'}';
}
}
Is there anything special about your app?
May transactions or multi-threading play a role?
Did you find any workarounds to prevent the issue?
From a first look: make sure that new File(sdkBaseDir) exists and you have permission to read and write to it.
Note: Internally this error code (MDB_PAGE_NOTFOUND) has the message Requested page not found - this usually indicates corruption attached. Though @greenrobot can probably say more.
-ut
From a first look: make sure that
new File(sdkBaseDir)exists and you have permission to read and write to it.Note: Internally this error code has the message
Requested page not found - this usually indicates corruptionattached. Though @greenrobot can probably say more.
-ut
Thanks for your reply @greenrobot-team .
@greenrobot-team
I uploaded the demo to reproduce the exception, use the same database file.
TestObjextBox.zip
Thanks, I reported this internally to the development team.
-ut
@wizardmly Do you have a reproducible way to bring the database into that state where you cannot put anymore?
@wizardmly Do you have a reproducible way to bring the database into that state where you cannot put anymore?
Sorry for that, I'm not sure when it happens, because this is accidental until the database enter the state.
@wizardmly Does this affect a specific device or Android Version? Does this happen after restarting the device?
We found the same problem. Our application works on a cash register device, Summi T2mini_s, Android 7.1.1. ObjectBox cannot read data, the following error occurred while writing data:
=======================================================
2020-02-11 18: 05: 05.314 7451-7513 / com.revisit.accountsystem W / System.err: io.objectbox.exception.DbException: Could not get from cursor (-30797) (error code -30797)
2020-02-11 18: 05: 05.314 7451-7513 / com.revisit.accountsystem W / System.err: at io.objectbox.query.Query.nativeFindKeysUnordered (Native Method)
2020-02-11 18: 05: 05.314 7451-7513 / com.revisit.accountsystem W / System.err: at io.objectbox.query.Query $ 5.call (Query.java:245)
2020-02-11 18: 05: 05.314 7451-7513 / com.revisit.accountsystem W / System.err: at io.objectbox.query.Query $ 5.call (Query.java:242)
2020-02-11 18: 05: 05.314 7451-7513 / com.revisit.accountsystem W / System.err: at io.objectbox.Box.internalCallWithReaderHandle (Box.java:626)
2020-02-11 18: 05: 05.314 7451-7513 / com.revisit.accountsystem W / System.err: at io.objectbox.query.Query.findIds (Query.java:242)
2020-02-11 18: 05: 05.314 7451-7513 / com.revisit.accountsystem W / System.err: at com.revisit.accountsystem.sync_data.SyncDataBean.lambda $ save $ 2 (SyncDataBean.java:337)
2020-02-11 18: 05: 05.314 7451-7513 / com.revisit.accountsystem W / System.err: at com.revisit.accountsystem.sync_data .- $$ Lambda $ SyncDataBean $ 9lUgoNQI-WjHkAHe-oAL-oY8HMs.run (lambda)
2020-02-11 18: 05: 05.314 7451-7513 / com.revisit.accountsystem W / System.err: at io.objectbox.BoxStore.runInTx (BoxStore.java:602)
2020-02-11 18: 05: 05.314 7451-7513 / com.revisit.accountsystem W / System.err: at com.revisit.accountsystem.sync_data.SyncDataBean.save (SyncDataBean.java:204)
2020-02-11 18: 05: 05.314 7451-7513 / com.revisit.accountsystem W / System.err: at com.revisit.accountsystem.sync_data.SyncManager.updateOnlineData (SyncManager.java:323)
2020-02-11 18: 05: 05.314 7451-7513 / com.revisit.accountsystem W / System.err: at com.revisit.accountsystem.sync_data.SyncManager.sync (SyncManager.java:227)
2020-02-11 18: 05: 05.315 7451-7513 / com.revisit.accountsystem W / System.err: at com.revisit.accountsystem.device_login.FragmentDeviceLogin $ 2.run (FragmentDeviceLogin.java:295)
=======================================================
code segment
=======================================================
Query query = orderItemBox.query (). Equal (EntityOrderItem_.orderId, order.getId ()). NotIn (EntityOrderItem_.id, orderItemIds) .build () query.remove ();
=======================================================
Errors always appear
I found that the problem lies in the storage path
This problem occurs when I save the file in Environment.getExternalStorageDirectory ().
If stored in App.getContext (). GetCacheDir () then the program runs normally
Closing this issue due to inactivity. :zzz: Feel free to re-open with more details or submit a new issue.
Note that 2.7.0 has some database validation tools that may help with unreliable file systems that are the likely cause of this issue.
Most helpful comment
I found that the problem lies in the storage path
This problem occurs when I save the file in Environment.getExternalStorageDirectory ().
If stored in App.getContext (). GetCacheDir () then the program runs normally