SQLite:从命令行插入二进制数据 [英] SQLite: insert binary data from command line
问题描述
我有这个SQLite表:
I have this SQLite table:
create table mytable (
aid INTEGER NOT NULL PRIMARY KEY,
bid INTEGER NOT NULL,
image BLOB
);
我想在此表的image
字段中插入一个二进制文件.是否可以从sqlite3
命令行界面执行此操作?如果是这样,怎么办?我正在使用Ubuntu.
And I want to insert a binary file into the image
field in this table. Is it possible to do it from the sqlite3
command line interface? If so, how? I'm using Ubuntu.
谢谢!
推荐答案
您可以使用以下语法:
echo "insert into mytable values(1,1, \"`cat image`\")" | sqlite3 yourDb
我不确定blob周围的值.请注意cat命令周围的反引号,这意味着cat命令将在回显之前执行.
i'm not sure for the " around blob's value. Note the backquotes around cat command, means the cat command will be executed before the echo.
Blob存储为带有"X"前缀的十六进制数字.您可以使用"hexdump" unix命令生成十六进制字符串,但是最好编写一个命令行工具来读取图像并进行插入. 有关此帖子的更多详细信息: http://comments.gmane.org/gmane .comp.db.sqlite.general/64149
Blob are stored as hexa digit with "X" prefix. You can use "hexdump" unix command to produce the hexa string, but it would be better to write a command line tool that read image and do the insert. More details on this post : http://comments.gmane.org/gmane.comp.db.sqlite.general/64149
这篇关于SQLite:从命令行插入二进制数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!