【问题标题】:Saving Blob data from SQLite database to a file将 Blob 数据从 SQLite 数据库保存到文件
【发布时间】:2011-02-14 07:07:08
【问题描述】:

我正在尝试将 SQLite 数据库(Safari 缓存:Cache.db)中的 blob 数据保存到文件中,但由于某种原因,sqlite 不会读取整个 blob。我最终想在 ruby​​ 中执行此操作,但现在直接在 sqlite 命令提示符下工作的东西很好。另外,我已经阅读了关于 stackoverflow 的所有条目,但其中大多数只讨论了将图像保存在 blob 中的性能,并且确实显示将 blob 保存到文件的条目是在 C# 中,这没有帮助我。这是我尝试过的:

sqlite> select * from cfurl_cache_response limit 1; 3501|0|945281827|0|http://www.gospelz.com/components/com_jomcomment/smilies/guest.gif|2010-02-24 16:20:07

sqlite> 从 cfurl_cache_blob_data 中选择 receiver_data,其中 entry_ID = 3501;
GIF89a(

原始 (guest.gif) 文件的 hexdump 显示 sqlite 在第一个空值后停止读取 blob:

$ hexdump -C guest.gif
00000000 47 49 46 38 39 61 28 00 28 00 f7 00 00 f1 f5 fd |GIF89a(.(.......|

sqlite> .output test.gif
sqlite> 从 cfurl_cache_blob_data 中选择 receiver_data,其中 entry_ID = 3501;
$ hexdump -C test.gif
00000000 47 49 46 38 39 61 28 0a |GIF89a(.|

【问题讨论】:

    标签: ruby sqlite blob


    【解决方案1】:

    SQLite3 正在读取整个 blob,但 sqlite shell 程序仅显示到 NUL。

    要对此进行测试,您可以尝试:

    select hex( receiver_data ) from cfurl_cache_blob_data where entry_ID = 3501;
    

    【讨论】:

    【解决方案2】:

    在 Ruby 中从 blob 或原始二进制文件生成文件非常简单。你这样做的方式与写入文件的方式相同。例如,要创建一个 jpeg:

    File.open("image_name.jpg", 'w') {|f| f.write raw_blob_content } 
    

    【讨论】:

      猜你喜欢
      • 2021-06-05
      • 1970-01-01
      • 1970-01-01
      • 2014-04-07
      • 2011-09-11
      • 2012-01-18
      • 2013-07-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多