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.
How can I alter this so that all the images are saved instead of just 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
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.