Skip to content

Commit

Permalink
fix #2855: delete big comments and truncate new inserted comments
Browse files Browse the repository at this point in the history
  • Loading branch information
maxme committed Jun 18, 2015
1 parent 661dc4f commit bf3cd76
Showing 1 changed file with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteStatement;

import org.wordpress.android.util.AppLog.T;

import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -118,4 +120,21 @@ public static boolean dropAllTables(SQLiteDatabase db) throws SQLiteException {
db.endTransaction();
}
}

/*
* Android's CursorWindow has a max size of 2MB per row which can be exceeded
* with a very large text column, causing an IllegalStateException when the
* row is read - prevent this by limiting the amount of text that's stored in
* the text column.
* https://github.com/android/platform_frameworks_base/blob/b77bc869241644a662f7e615b0b00ecb5aee373d/core/res/res/values/config.xml#L1268
* https://github.com/android/platform_frameworks_base/blob/3bdbf644d61f46b531838558fabbd5b990fc4913/core/java/android/database/CursorWindow.java#L103
*/
private static final int MAX_TEXT_LEN = 1024 * 1024;
public static String maxSQLiteText(final String text) {
if (text.length() <= MAX_TEXT_LEN) {
return text;
}
AppLog.w(T.UTILS, "sqlite > max text exceeded, storing truncated text");
return text.substring(0, MAX_TEXT_LEN);
}
}

0 comments on commit bf3cd76

Please sign in to comment.