Nozbe / WatermelonDB

🍉 Reactive & asynchronous database for powerful React and React Native apps ⚡️
https://watermelondb.dev
MIT License
10.62k stars 600 forks source link

@nozbe/watermelondb Error: Row too big to fit into CursorWindow requiredPos=4, totalRows=5 #1721

Open HanHuynh91 opened 11 months ago

HanHuynh91 commented 11 months ago

Query Select throw error Error: Row too big to fit into CursorWindow requiredPos=4, totalRows=5 in watermelondb in react native app

joaosodres commented 7 months ago

Same problem here, how did you solve it?

henrypadua commented 7 months ago

Hello @joaosodres and @joaosodres, follow the solution below:

Go to android/app/src/main/java and in your MainActivity.kt or MainApplication.java on method onCreate and add the import and code below

For Kotlin:

// The import must be use on the top togheter others imports
import android.database.CursorWindow

try {
      val field = CursorWindow::class.java.getDeclaredField("sCursorWindowSize")
      field.isAccessible = true
      field.set(null, 100 * 1024 * 1024) //the 100MB is the new size
    } catch (e: Exception) {
      if (DEBUG_MODE) {
        e.printStackTrace()
      }
    }

example image

For Java:

// The import must be use on the top togheter others imports
import android.database.CursorWindow;
import java.lang.reflect.Field;

try {
  Field field = CursorWindow.class.getDeclaredField("sCursorWindowSize");
  field.setAccessible(true);
  field.set(null, 100 * 1024 * 1024); // 100MB is the new size
} catch (Exception e) {
  if (BuildConfig.DEBUG) {
    e.printStackTrace();
  }
}

example image

radex commented 6 months ago

Would highly encourage anyone to contribute these snippets by @henrypadua to the official docs under Android troubleshooting

joaosodres commented 6 months ago

Unfortunately I've already done that and it didn't work

PeterKucera commented 1 month ago

If you're using Expo - following config plugin helped me increase CursorWindow size - link

I took inspiration from following sources:

  1. https://github.com/andpor/react-native-sqlite-storage/issues/364
  2. https://github.com/expo/expo/issues/23629
  3. https://docs.expo.dev/config-plugins/introduction/

Don't forget to add plugin to your app.config.ts

 plugins: [
    ["./plugins/withAndroidMainActivity"],
  ]

and run npx expo prebuild

wesleygomess commented 1 week ago

Hollo @henrypadua, Thank you very much my friend, your solution worked very well, it fixed the bug in production, God bless you, success