How to dump a file stored in a sqlite database as a blob?

前端 未结 4 691
慢半拍i
慢半拍i 2020-12-13 06:32

I have a sqlite3 database. One column has the TEXT type, and contains blobs which I would like to save as file. Those are gzipped files.

The output of the command

4条回答
  •  遥遥无期
    2020-12-13 07:03

    I had to make some minor changes on CL's answer, in order to make it work for me:

    • The structure for the command that he is using does not have the database name in it, the syntax that I am using is something like:

      sqlite3 mydatabase.sqlite3 "Select quote(BlobField) From TableWithBlod Where StringKey = '1';" | ...
      
    • The way he is using the cut command does not work in my machine. The correct way for me is:

      cut -d "'" -f2
      

    So the final command would be something like:

    sqlite3 mydatabase.sqlite3 "Select quote(BlobField) From TableWithBlod Where StringKey = '1';" | cut -d "'" -f2 | xxd -r -p > myfile.extension
    

    And in my case:

    sqlite3 osm-carto_z14_m8_m.mbtiles "select quote(images.tile_data) from images where images.tile_id = '1';" | cut -d "'" -f2 | xxd -r -p > image.png
    

提交回复
热议问题