Skip to content

Commit

Permalink
Gracefully handles "android.database.sqlite.SQLiteException: Row too …
Browse files Browse the repository at this point in the history
…big to fit into CursorWindow" crash
  • Loading branch information
rcidt committed Feb 28, 2023
1 parent 43d989f commit e94e02f
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public WritableMap getContactByRawId(String contactRawId) {
/*contact id not found */
}

if (rawCursor.moveToNext()) {
if (cursorMoveToNext(rawCursor)) {
int columnIndex;
columnIndex = rawCursor.getColumnIndex(ContactsContract.RawContacts.CONTACT_ID);
if (columnIndex == -1) {
Expand Down Expand Up @@ -304,12 +304,20 @@ public WritableArray getContacts() {
return contacts;
}

private Boolean cursorMoveToNext(Cursor cursor) {
try {
return cursor.moveToNext();
} catch(RuntimeException error) {
return false;
}
}

@NonNull
private Map<String, Contact> loadContactsFrom(Cursor cursor) {

Map<String, Contact> map = new LinkedHashMap<>();

while (cursor != null && cursor.moveToNext()) {
while (cursor != null && cursorMoveToNext(cursor)) {

int columnIndexContactId = cursor.getColumnIndex(ContactsContract.Data.CONTACT_ID);
int columnIndexId = cursor.getColumnIndex(ContactsContract.Data._ID);
Expand Down Expand Up @@ -573,7 +581,7 @@ public String getPhotoUriFromContactId(String contactId) {
null
);
try {
if (cursor != null && cursor.moveToNext()) {
if (cursor != null && cursorMoveToNext(cursor)) {
String rawPhotoURI = cursor.getString(cursor.getColumnIndex(Contactables.PHOTO_URI));
if (!TextUtils.isEmpty(rawPhotoURI)) {
return rawPhotoURI;
Expand Down

0 comments on commit e94e02f

Please sign in to comment.