gpt4 book ai didi

sql - 如何在不读取 BLOB 内容的情况下获取 BLOB 的大小

转载 作者:IT王子 更新时间:2023-10-29 06:29:19 26 4
gpt4 key购买 nike

关于 sqlite 中的 BLOB,我有以下问题:

  • sqlite 是否跟踪 BLOB 的大小?
  • 我猜它确实如此,但是,长度函数是使用它,还是读取 BLOB 的内容?
  • 如果 sqlite 跟踪 BLOB 的大小但 length 不使用它,是否可以通过其他一些功能访问该大小?

我问这个是因为我想知道我是否应该在附加列中实现设置 BLOB 大小的触发器,或者我是否可以动态获取大小而不会影响 sqlite 读取 BLOB 的性能。

最佳答案

来源:

** In an SQLite index record, the serial type is stored directly before
** the blob of data that it corresponds to. In a table record, all serial
** types are stored at the start of the record, and the blobs of data at
** the end. Hence these functions allow the caller to handle the
** serial-type and data blob seperately.
**
** The following table describes the various storage classes for data:
**
** serial type bytes of data type
** -------------- --------------- ---------------
** 0 0 NULL
** 1 1 signed integer
** 2 2 signed integer
** 3 3 signed integer
** 4 4 signed integer
** 5 6 signed integer
** 6 8 signed integer
** 7 8 IEEE float
** 8 0 Integer constant 0
** 9 0 Integer constant 1
** 10,11 reserved for expansion
** N>=12 and even (N-12)/2 BLOB
** N>=13 and odd (N-13)/2 text

换句话说,blob的大小是连续的,它的长度就是“(serial_type-12)/2”。
此序列存储在实际 blob 之前,因此您无需读取 blob 即可获取其大小。
调用 sqlite3_blob_open 然后调用 sqlite3_blob_bytes 来获取这个值。

关于sql - 如何在不读取 BLOB 内容的情况下获取 BLOB 的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6899363/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com