sqlite get field with more than 2 MB [duplicate]

落花浮王杯 提交于 2019-12-20 07:39:43

问题


When I try to get data from SQlite and size of field more than 2 MB it throw exception

"Couldn't read row 0, col 0 from Cursor Window. Make sure the Cursor is initialized correctly before accessing data from it."

How can I store a field that have above 2 Mb get into string ?

i store multiple Base64 Strings as LONG TEXT in sqlite it store successfully but when i fatch from database that goes into exception because of that field contain above 2400000 characters.

this is the code

public ArrayList<HashMap<String, String>> selectRecordFromDbList(String qry, String[] args, boolean status) {
        ArrayList<HashMap<String, String>> arraylist = null;
        try {
            HashMap<String, String> mapRow;
            Cursor cursor = sqLiteDatabase.rawQuery(qry, args);
            if (cursor.moveToFirst()) {
                arraylist = new ArrayList<>();
                do {
                    mapRow = new HashMap<>();
                    for (int i = 0; i < cursor.getColumnCount(); i++) {
                        mapRow.put(cursor.getColumnName(i), cursor.getString(i));
                    }
                    arraylist.add(mapRow);
                } while (cursor.moveToNext());
            }
            if (cursor != null && cursor.isClosed()) {
                cursor.close();
            }
        } catch (Exception e) {
            Log.e("SqliteAssetHelper:", e.getMessage());
            arraylist = null;

        }
        return arraylist;
    }

回答1:


It is not advisable to store large BLOBS or similar data in the SQLite database. You should use the file system and only store a reference to the data in you database. Refer to this answer



来源:https://stackoverflow.com/questions/45892920/sqlite-get-field-with-more-than-2-mb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!