简体   繁体   English

将所有Blob从sqlite导出到文件

[英]Exporting all blobs from sqlite to a files

Using this command: 使用此命令:

sqlite3 my.db "SELECT writefile('object0.jpg', MyBlob) FROM MyTable WHERE id = 1"    

I can save an image stored as blob in a table in my db. 我可以将存储为blob的图像保存在数据库的表中。
How can I alter this so that all the images are saved instead of just 1? 如何更改此设置,以便保存所有图像而不是仅保存1张?

使用SQL字符串串联( || )构造文件名:

sqlite3 my.db "SELECT writefile('object' || id || '.jpg', MyBlob) FROM MyTable"   

If a two-step, naive solution is an option, you could do: 如果可以选择两步,天真的解决方案,则可以执行以下操作:

sqlite3 my.db "SELECT id from MyTable" > /tmp/id.list

for getting the list of all ids, then 获取所有ID的列表,然后

cat /tmp/id.list | while read id; do echo SELECT writefile\(\'object$id.jpg\', MyBlob\) FROM MyTable WHERE id = $id\;; done | sqlite3 my.db

for creating and executing commands for storing all the blobs. 用于创建和执行用于存储所有Blob的命令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM