SQLite: insert binary data from command line

情到浓时终转凉″ 提交于 2019-12-05 06:03:57

You may use a syntax like :

echo "insert into mytable values(1,1, \"`cat image`\")" | sqlite3 yourDb

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.

[EDIT]

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

The sqlite3 command line interface adds the following two “application-defined” functions:

  • readfile
    which typically is used as: INSERT INTO table(blob) VALUES (readfile('myimage.jpg'))
  • writefile
    which writes a file with the contents of a database blob and returns the bytes written.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!