Sqlite:如何为 BLOB 转换(数据为文本)

Sqlite: How to cast(data as TEXT) for BLOB(Sqlite:如何为 BLOB 转换(数据为文本))
本文介绍了Sqlite:如何为 BLOB 转换(数据为文本)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 sqlite 数据库,我想从中提取数据类型为 BLOB 的信息列.我正在尝试这个:

I have a sqlite database from which I want to extract a column of information with the datatype BLOB. I am trying this:

SELECT cast(data as TEXT) FROM content

这显然行不通.输出是这样的乱码:

This is obviously not working. The output is garbled text like this:

x Uak 0? > 8 0Ff;I . .i׮% A s M

内容列中的数据主要是文本,但也可能有图像(我认识到如果我将其转换为文本可能会导致问题).我只是想将该数据提取为可用格式.有什么想法吗?

The data in the content column is mostly text, but may also have images (which I recognized could cause a problem if I cast as TEXT). I simply want to extract that data into a usable format. Any ideas?

推荐答案

可以使用

SELECT hex(data) FROM content

SELECT quote(data) FROM content

第一个将返回一个十六进制字符串(ABCD),第二个将作为 SQL 文字引用(X'ABCD').

The first will return a hex string (ABCD), the second quoted as an SQL literal (X'ABCD').

请注意,(目前)无法将十六进制列信息转换回 SQLite 中的 BLOB.您将不得不使用 C/Perl/Python/... 绑定来转换和导入它们.

Note that there's (currently) no way of converting hexadecimal column information back to a BLOB in SQLite. You will have to use C/Perl/Python/… bindings to convert and import those.

这篇关于Sqlite:如何为 BLOB 转换(数据为文本)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

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

相关文档推荐

FastAPI + Tortoise ORM + FastAPI Users (Python) - Relationship - Many To Many(FastAPI+Tortoise ORM+FastAPI用户(Python)-关系-多对多)
Window functions not working in pd.read_sql; Its shows error(窗口函数在pd.read_sql中不起作用;它显示错误)
(Closed) Leaflet.js: How I can Do Editing Geometry On Specific Object I Select Only?((已关闭)Leaflet.js:如何仅在我选择的特定对象上编辑几何图形?)
in sqlite update trigger with multiple if/Case Conditions(在具有多个IF/CASE条件的SQLite UPDATE触发器中)
Android: Why is Room so slow?(Android:为什么Room这么慢?)
Remote Procedure call failed with sql server 2008 R2(使用 sql server 2008 R2 的远程过程调用失败)