morenoh149 / react-native-contacts

React Native Contacts
MIT License
1.65k stars 565 forks source link

android.database.sqlite.SQLiteException: Row too big to fit into CursorWindow requiredPos=158, totalRows=159 #694

Closed chengweibo closed 1 year ago

chengweibo commented 2 years ago

version 5.2.8 crash message

Caused by android.database.sqlite.SQLiteException: Row too big to fit into CursorWindow requiredPos=158, totalRows=159
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:186)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:142)
at android.database.BulkCursorProxy.getWindow(BulkCursorProxy.java:166)
at android.database.BulkCursorToCursorAdaptor.onMove(BulkCursorToCursorAdaptor.java:82)
at android.database.AbstractCursor.moveToPosition(AbstractCursor.java:248)
at android.database.AbstractCursor.moveToNext(AbstractCursor.java:280)
at android.database.CursorWrapper.moveToNext(CursorWrapper.java:206)
at com.rt2zz.reactnativecontacts.ContactsProvider.loadContactsFrom(ContactsProvider.java:311)
at com.rt2zz.reactnativecontacts.ContactsProvider.getContacts(ContactsProvider.java:287)
at com.rt2zz.reactnativecontacts.ContactsManager$1.doInBackground(ContactsManager.java:98)
at com.rt2zz.reactnativecontacts.ContactsManager$1.doInBackground(ContactsManager.java:91)
at android.os.AsyncTask$3.call(AsyncTask.java:394)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:305)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:923)
 private void getAllContacts(final Promise promise) {
        AsyncTask<Void,Void,Void> myAsyncTask = new AsyncTask<Void,Void,Void>() {
            @Override
            protected Void doInBackground(final Void ... params) {
                Context context = getReactApplicationContext();
                ContentResolver cr = context.getContentResolver();

                ContactsProvider contactsProvider = new ContactsProvider(cr);
                WritableArray contacts = contactsProvider.getContacts();
                promise.resolve(contacts);
                return null;
            }
        };
        myAsyncTask.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
    } 

need try catch this code "contactsProvider.getContacts(); " or repair as follows: https://stackoverflow.com/questions/51959944/sqliteblobtoobigexception-row-too-big-to-fit-into-cursorwindow-requiredpos-0-t

public void testRowTooBig() {
        mDatabase.execSQL("CREATE TABLE Tst (Txt BLOB NOT NULL);");
        byte[] testArr = new byte[10000];
        Arrays.fill(testArr, (byte) 1);
        for (int i = 0; i < 10; i++) {
            mDatabase.execSQL("INSERT INTO Tst VALUES (?)", new Object[]{testArr});
        }
        // Now reduce window size, so that no rows can fit        Cursor cursor = mDatabase.rawQuery("SELECT * FROM TST", null);
        CursorWindow cw = new CursorWindow("test", 5000);
        AbstractWindowedCursor ac = (AbstractWindowedCursor) cursor;
        ac.setWindow(cw);
        try {
            ac.moveToNext();
            fail("Exception is expected when row exceeds CursorWindow size");
        } catch (SQLiteBlobTooBigException expected) {
        }
    }
morenoh149 commented 2 years ago

that sounds good, submit it as a pr

github-actions[bot] commented 1 year ago

This issue is stale, please provide more information about the status