SQLiteBlobTooBigException:写入数据库时​​行太大而无法放入 CursorWindow [英] SQLiteBlobTooBigException: Row too big to fit into CursorWindow while writing to DB

查看:460
本文介绍了SQLiteBlobTooBigException:写入数据库时​​行太大而无法放入 CursorWindow的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试在 android 上添加 sqllite 数据库时看到上述错误.我正在使用 cloudant 库.这是堆栈跟踪:

I see the above error when I try to add to sqllite DB on android.I am using cloudant library. Here's the stack trace:

2019-07-17 18:04:48.292 5522-5753/org.iprd.identity E/SQLiteQuery: exception: Row too big to fit into CursorWindow requiredPos=0, totalRows=1; query: SELECT docs.docid, docs.doc_id, revid, sequence, current, deleted, parent, json FROM revs, docs WHERE docs.docid=? AND revs.doc_id=docs.doc_id AND revid=? ORDER BY revs.sequence LIMIT 1
2019-07-17 18:04:48.302 5522-5522/org.iprd.identity E/DatabaseImpl: Failed to create document
    java.util.concurrent.ExecutionException: android.database.sqlite.SQLiteBlobTooBigException: Row too big to fit into CursorWindow requiredPos=0, totalRows=1
        at java.util.concurrent.FutureTask.report(FutureTask.java:123)
        at java.util.concurrent.FutureTask.get(FutureTask.java:193)
        at com.cloudant.sync.internal.documentstore.DatabaseImpl.get(DatabaseImpl.java:1084)
        at com.cloudant.sync.internal.documentstore.DatabaseImpl.create(DatabaseImpl.java:925)

我以前从未遇到过这个问题,但是,我最近进行了更改并开始使用 3rd 方工具为我提供一些图像.使用这个新工具,图像尺寸似乎比以前大得多.我通过对图像进行 Base64 编码将这些图像作为字符串存储在我的数据库中.但是,使用这个新工具,在存储图像时,我得到了上述异常.

I never got this issue previously, however, I recently made a change and started using a 3rd party tool to give me some images. With this new tool, the image sizes seem to be much bigger than before. I am storing these images in my db as a string by doing a Base64 encoding of the image. However, with this new tool, while storing the image, I get the above exception.

我有一个单元测试,我尝试使用从该图像生成的字符串之一,但这也引发了一个错误,即字符串大小太大,甚至无法编译.

I have a unit test which I tried using one of the generated strings from this image, but that also throws an error that the string size is too large and does not even compile.

解决这个问题的最佳方法是什么?-

What is the best approach to solve this? -

  1. 我想做的是将图像存储在设备本身中,并将路径存储在数据库中.

  1. What I was thinking of doing is to store the image in the device itself and just store the path in the DB.

是否可以对图像进行一些压缩以减小其文件大小?

Is there some compression we can do to the image to reduce its file size?

是否可以调整一些数据库设置以确保它可以处理更大的图像尺寸?

Is it possible to tune some db setting to ensure that it can handle larger image sizes?

提前致谢!

推荐答案

我想做的是将图像存储在设备中本身并将路径存储在数据库中.

What I was thinking of doing is to store the image in the device itself and just store the path in the DB.

不打算回答,因为你最适合回答这个问题.

Not going to answer, as you are the best to answer that question.

是否可以对图像进行一些压缩以减少其文件尺寸?

Is there some compression we can do to the image to reduce its file size?

可能,但这并不一定能消除问题.即使您将图像压缩为 2Mb(光标窗口的 4Mb 限制的一半),那么一次可能只有 1 行适合光标窗口.结果很可能是非常糟糕的性能,而且瓶头并不是真正的 SQLite,而是处理 Cursor.

Possibly but that isn't necessarily going to eliminate the problem. As even if you compressed the images to say 2Mb (half the 4Mb limit of a Cursor Window ) then the likeliehood is that only 1 row would fit into a cursor window at a time. The result would likely be very poor performance and the bottlehead isn't really SQLite but handling the Cursor.

  • 不推荐

另一种解决方案,但仍然很昂贵,将图像存储在部分/块中,可以找到这样做的示例(注意没有进行调整来建立 256kb 卡盘大小)这里.注意到响应时间很差.

Another solution, but still costly, would be to store the image in parts/chunks, an example of doing so (noting that no tuning was undertaken to establish the 256kb chucksize) can be found here. Noting that the response time, is considered very poor.

  • 不推荐,但如果性能不佳不是问题,那么可能是一个解决方案
  • not recommended but if poor performance is not an issue then could be a solution

不需要额外压缩/解压缩开销的解决方案是在文件系统(例如外部存储)中存储超过设定大小的图像或图像,并存储路径或路径的一部分.

The solution that doesn't require the overheads of additional compression/decompsression is to store images or images over a set size in the file system (e.g. external storage) and store the path or a part of the path.

  • 后一种选择,将小图像存储在数据库中,将大图像存储为文件,可以利用 比文件系统快 35%).

在此处回答.

  • 注意此示例可用作仅存储路径或混合解决方案的基础.
  • Note this example could be used as the basis for both just storing paths or for a mixed solution.

推荐

是否可以调整一些数据库设置以确保它可以处理更大的图像尺寸?

Is it possible to tune some db setting to ensure that it can handle larger image sizes?

是的.

你可以考虑:-

  • optimising your queries. See, as a start, EXPLAIN QUERY PLAN and The SQLite Query Optimizer Overview
  • increasing the page size (noting the limitations as when),
  • increasing the cache size,
  • risk turning synchronous to off and
  • risk using exclusive locking.
  • compiling your own tuned version of SQLite applying compile time options to suit.
  • further reading the above links as there may be additional applicable tuning settings.

这篇关于SQLiteBlobTooBigException:写入数据库时​​行太大而无法放入 CursorWindow的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆