-
Notifications
You must be signed in to change notification settings - Fork 519
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Row too big to fit into CursorWindow #364
Comments
|
I'm seeing the same error: ...but it only started happening after upgrading the test device to android 9.0 (from 8 I think). React Native SQLite Storage Version used: 3.3.3 (which is obviously a little old now). Android 9.0 is implicated by the joplin tickets too. |
|
These links discuss this problem and suggest some solutions: https://stackoverflow.com/questions/51959944/sqliteblobtoobigexception-row-too-big-to-fit-into-cursorwindow-requiredpos-0-t |
|
There's a warning before the error: We've got BLOBs in each row, some of which are around this size. This is for an app with many existing users, so we can't just make the rows smaller somehow. |
|
can you attach full native debug log. |
|
@andpor try {
Field field = CursorWindow.class.getDeclaredField("sCursorWindowSize");
field.setAccessible(true);
field.set(null, 100 * 1024 * 1024); //the 100MB is the new size
} catch (Exception e) {
if (DEBUG_MODE) {
e.printStackTrace();
}
}Note that it requires Android 9 (API level 28). this work for me. |
|
https://stackoverflow.com/questions/11340257/sqlite-android-database-cursor-window-allocation-of-2048-kb-failed/50725977#50725977 mentions the above sCursorWindowSize fix. It will affect all code using CursorWindows across the whole application, so could easily make your application use too much memory. It's changing the value of this field: https://android.googlesource.com/platform/frameworks/base/+/f86bea9b4277d9fe2c1b8bfae872a8fad15c4dc1/core/java/android/database/CursorWindow.java#48, so will generate a warning: https://developer.android.com/distribute/best-practices/develop/restrictions-non-sdk-interfaces https://stackoverflow.com/questions/11340257/sqlite-android-database-cursor-window-allocation-of-2048-kb-failed/56887043#56887043 is an android P specific fix, that would allow a different window size to be used in each case, but requires a change to be made to the react-native-sqlite-storage application. The ideal solution is to change your application to keep the row size small, although that's generally not possible for an already-released application where users have large rows and upgrade to android 9. I've still not worked out why this only affects us (and others) on Android 9 and above - our rows can be too large for the default cursor window size, and it looks like this should have always been the case on every platform. The cursor window size defaults to the value of the com.android.internal.R.integer.config_cursorWindowSize android platform resource, which has been 2MB for some time (probably), for at least AOSP builds: https://stackoverflow.com/a/35012963 |
|
Anyone found a working fix for this? I've applied the one below, but users are still having the same error. |
|
Just hit this as well. The logs are below in case they help anyone. The SQL query executed is there as well and is executed when my app rehydrates the redux state (based on prsn's redux-persist-sqlite-storage package). The error only occurs the first time the app is opened after an upgrade. Otherwise, closing and re-opening the application doesn't trigger the error. The default 2MB limit for the CursorWindow applies here. |
|
For anyone having issues with this error you might want to check my comment here craftzdog/react-native-sqlite-2#57 (comment) |
You have to add the necessary imports import android.database.CursorWindow;
import java.lang.reflect.Field; |
I got an error for BTW Thanks, @roycechua23 for pointing the import issues. |
You may use this code: |
|
@bambinoua Thank you! 💯 I'll give it a try! |
I got |
Out of interest, is there any risk associated with increasing this limit so much (from 4MB -> 100MB)? Is this potentially going to cause other issues that we should watch out for? |
|
For the record I've implemented that fix a while back: try {
Field field = CursorWindow.class.getDeclaredField("sCursorWindowSize");
field.setAccessible(true);
field.set(null, 100 * 1024 * 1024); //the 100MB is the new size
} catch (Exception e) {
if (DEBUG_MODE) {
e.printStackTrace();
}
}And we're still getting the error now and then, so I'm not sure it's doing anything at all. |
Expected Behavior
The query with large data should succeed without an error.
Current Behavior
When trying to a do a SELECT on large rows, the query fails with error:
Steps to Reproduce (for bugs)
This is affecting several users of Joplin:
laurent22/joplin#1771
laurent22/joplin#1690
and it happens when trying to read or write to the database large text data (some users mention 4MB).
It seems to have started only recently so it could be due to a React Native upgrade or other change to the Android build.
What I'm wondering is, is there any way to prevent this error, for example some option that can be set to increase the available memory?
The Joplin desktop application uses the same architecture (but of course with a different sqlite package) and this error doesn't happen, so it seems it's possible to prevent it. 4MB is a bit large but not huge either so it seems it should work, at least with an option.
Your Environment
The text was updated successfully, but these errors were encountered: