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

How to obtain the size of a BLOB without reading the BLOB#39;s content(如何在不读取 BLOB 内容的情况下获取 BLOB 的大小)
本文介绍了如何在不读取 BLOB 内容的情况下获取 BLOB 的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have the following questions regarding BLOBs in sqlite:

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

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

I'm asking this because I'm wondering if I should implement triggers that set BLOBs' sizes in additional columns, of if I can obtain the sizes dynamically without the performance hit of sqlite reading the BLOBs.

推荐答案

来自:

** 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 来获取这个值.

In other words, the blob size is in the serial, and it's length is simply "(serial_type-12)/2".
This serial is stored before the actual blob, so you don't need to read the blob to get its size.
Call sqlite3_blob_open and then sqlite3_blob_bytes to get this value.

这篇关于如何在不读取 BLOB 内容的情况下获取 BLOB 的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Execute complex raw SQL query in EF6(在EF6中执行复杂的原始SQL查询)
Hibernate reactive No Vert.x context active in aws rds(AWS RDS中的休眠反应性非Vert.x上下文处于活动状态)
Bulk insert with mysql2 and NodeJs throws 500(使用mysql2和NodeJS的大容量插入抛出500)
Flask + PyMySQL giving error no attribute #39;settimeout#39;(FlASK+PyMySQL给出错误,没有属性#39;setTimeout#39;)
auto_increment column for a group of rows?(一组行的AUTO_INCREMENT列?)
Sort by ID DESC(按ID代码排序)