sqlite获取超过2 MB的字段 [英] sqlite get field with more than 2 MB
问题描述
当我尝试从SQlite获取数据并且字段大小超过2 MB时会抛出异常
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.
"
如何存储2 Mb以上的字段插入字符串?
How can I store a field that have above 2 Mb get into string ?
我在sqlite中将多个Base64字符串存储为LONG TEXT,成功存储了该字符串,但是当我从数据库中获取异常时,由于该字段包含2400000个以上的字符,因此出现异常.
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.
这是代码
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;
}
推荐答案
不建议在SQLite数据库中存储大型BLOBS或类似数据.您应该使用文件系统,并且仅在数据库中存储对数据的引用. 请参考 answer
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
这篇关于sqlite获取超过2 MB的字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!