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

5 sql sqlite triggers blob

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

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

我问这个是因为我想知道我是否应该实现在其他列中设置BLOBs大小的触发器,如果​​我可以动态获取大小而没有sqlite读取BLOB的性能损失.

Oli*_*iJG 5

从来源:

** 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
Run Code Online (Sandbox Code Playgroud)

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