Skip to content

Commit 4f48de6

Browse files
committed
fix #2855: delete big comments and truncate new inserted comments
1 parent 753f63d commit 4f48de6

File tree

1 file changed

+19
-0
lines changed
  • WordPressUtils/src/main/java/org/wordpress/android/util

1 file changed

+19
-0
lines changed

WordPressUtils/src/main/java/org/wordpress/android/util/SqlUtils.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import android.database.sqlite.SQLiteException;
88
import android.database.sqlite.SQLiteStatement;
99

10+
import org.wordpress.android.util.AppLog.T;
11+
1012
import java.util.ArrayList;
1113
import java.util.List;
1214

@@ -118,4 +120,21 @@ public static boolean dropAllTables(SQLiteDatabase db) throws SQLiteException {
118120
db.endTransaction();
119121
}
120122
}
123+
124+
/*
125+
* Android's CursorWindow has a max size of 2MB per row which can be exceeded
126+
* with a very large text column, causing an IllegalStateException when the
127+
* row is read - prevent this by limiting the amount of text that's stored in
128+
* the text column.
129+
* https://github.com/android/platform_frameworks_base/blob/b77bc869241644a662f7e615b0b00ecb5aee373d/core/res/res/values/config.xml#L1268
130+
* https://github.com/android/platform_frameworks_base/blob/3bdbf644d61f46b531838558fabbd5b990fc4913/core/java/android/database/CursorWindow.java#L103
131+
*/
132+
private static final int MAX_TEXT_LEN = 1024 * 1024;
133+
public static String maxSQLiteText(final String text) {
134+
if (text.length() <= MAX_TEXT_LEN) {
135+
return text;
136+
}
137+
AppLog.w(T.UTILS, "sqlite > max text exceeded, storing truncated text");
138+
return text.substring(0, MAX_TEXT_LEN);
139+
}
121140
}

0 commit comments

Comments
 (0)