我如何在sqlite中找到二进制blob的长度(大小) [英] How do I find the length (size) of a binary blob in sqlite
问题描述
我有一个包含BLOB文件的sqlite表,但是需要对blob进行大小/长度检查,我该怎么做?
I have an sqlite table that contains a BLOB file, but need to do a size/length check on the blob, how do I do that?
根据我发现的一些文档,使用length(blob)无效,因为length()仅适用于文本,并且在第一个NULL后将停止计数.我的经验测试表明这是正确的.
According to some documentation I did find, using length(blob) won't work, because length() only works on texts and will stop counting after the first NULL. My empirical tests have shown this to be true.
我正在使用SQLite 3.4.2
I'm using SQLite 3.4.2
更新:
因此,从SQLite 3.7.6开始,length()函数似乎返回了正确的blob值-我检查了sqlite的各种更改日志,但没有看到在哪个版本中得到了纠正.
So as of SQLite 3.7.6 it appears as though the length() function returns the correct value of blobs - I checked various change-logs of sqlite, but did not see in what version this was corrected.
从Sqlite 3.7.6开始:
From Sqlite 3.7.6:
payload_id|length(payload)|length(hex(payload))/2
1807913|194|194
1807914|171|171
文档已更改以反映这一点.
The documentation was changed to reflect this.
length(X) The length(X) function returns the length of X in characters if X is
a string, or in bytes if X is a blob. If X is NULL then length(X) is
NULL. If X is numeric then length(X) returns the length of a string
representation of X.
推荐答案
没有此问题,但是您可以尝试length(hex(glob))/2
haven't had this problem, but you could try length(hex(glob))/2
更新(2012年8月):
对于SQLite 3.7.6(2011年4月12日发布)及更高版本,length(blob_column)
可以像文本和二进制数据一样正常工作.
Update (Aug-2012):
For SQLite 3.7.6 (released April 12, 2011) and later, length(blob_column)
works as expected both both text and binary data.
这篇关于我如何在sqlite中找到二进制blob的长度(大小)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!