SQL 数据库中 TEXT 类型的行可以有多大(以 KB 为单位)?
我正在使用 Base64 将图像编码为字符串,并将这些图像上传到远程数据库中,位于表 USER 的一行中。该行是 TEXT,因为我不知道是否还有另一个 String 类型具有比 TEXT 更多的空间。
当我存储非常小的图像(具有 5 或 10 KB 的空间)时,它们存储正常,当我将这些图像从 sql DB 返回到我的应用程序时,我可以将它们解码为 BitMap 并将它们显示到 ImageView 中。
问题:当我存储具有例如 110 KB 空间的图像时,我认为它们在 SQL DB 中的 USER 表的 TEXT 行中存储不正常,因为当我尝试解码它们时,我得到一个错误,它们无法解码,但我不知道为什么,因为Base64的解码函数在无法解码时只是返回null。
有办法解决我的问题吗?
SQL 数据库中 TEXT 类型的行可以有多大(以 KB 为单位)?
使用 TEXT 是最好的选择吗?或者还有另一种类型可以存储更长的字符串(例如大于100KB)?
谢谢
i'm encodding images with Base64 into Strings, and i am uploading these images into a remote database, in a row of the table USER. That row is TEXT, because i dont know if there is anothr String type with more space than TEXT.
When i store very small images, with 5 or 10 KB of space, they store OK, and when i get these images back from the sql DB into my app, i can decode them into BitMap and show them into a ImageView.
THE PROBLEM: When i store images with for example 110 KB of space, i think they doesn't store OK in the TEXT row of my table USER in the SQL DB, because when i try to decode them, i got an error, they can't be decoded, but i dont know why, because the decode function of Base64 simply returns null when he can't decode.
There is a way to solve my problem?
How large (in KB) can a TEXT-type row be in an SQL DB?
Is using TEXT the best option here? Or there is another Type that can store much longer Strings (eg much larger than 100KB)?
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我会使用 BLOB 而不是 TEXT。
不过我认为更好的方法是将图像路径存储在数据库中,而图像存储在 SDCard 上。原因是 DB 存储在设备内存中(在许多情况下,只有 20 - 50 MB 可用)。因此,如果有大量图像,则可以利用整个内部存储器,从而使整个设备几乎无法操作。
I would use BLOB instead of TEXT.
However I think the better approach would be to store image pathes in the DB while the images are stored on SDCard. The reason for this is DB is stored on device internal memory (in many cases it is just 20 - 50 MB available). So if there are lots of images, then it is possible to utilize whole internal memory making the entire device almost unoperatable.
当您将数据插入标记为 TEXT 的列时,它会转换为支持的字符编码之一。您应该查看 SQLite 3 数据类型定义。我想您会希望将数据存储在 BLOB 中,因为您希望存储原始数据而不考虑实际的编码字符串。
When you insert data into a column marked TEXT, it gets converted to one of the supported character encodings. You should take a look at the SQLite 3 Datatypes definitions. I would imagine you would want your data stored in a BLOB since you want the raw data to be stored without regard to the actual encoded string.