【问题标题】:Inserting and displaying image as BLOB file in SQLite在 SQLite 中将图像插入和显示为 BLOB 文件
【发布时间】:2012-03-29 00:40:00
【问题描述】:

这就是我使用 sqlite 创建数据库的方式

Pro:~ dd$ sqlite3 db.db
SQLite version 3.7.7 2011-06-25 16:35:41
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> create table cus(id integer primary key, firstname varchar(30));
sqlite> inser into cus(firstname)values('f');
Error: near "inser": syntax error
sqlite> insert into cus(firstname)values('f');
sqlite> select * from cus;
1|f
sqlite> 

现在我需要插入图像,我读到我们可以将图像保存为BLOB 文件,有人可以告诉我如何将图像保存到数据库文件并检索图像并显示在imageview 中吗?教程或示例代码

【问题讨论】:

    标签: iphone objective-c sqlite


    【解决方案1】:

    最好将磁盘上文件的路径或相对路径存储在数据库中。文件系统针对加载和存储 Blob 数据进行了优化,而数据库针对关系数据进行了优化,以便以事务方式查询和存储。

    它允许您在控制图像的内存占用(以及您选择缓存的内容和方式)的同时保持数据库小巧轻便。

    相关帖子:

    Android sqlite / BLOB perfomance issue

    http://groups.google.com/group/alt.comp.lang.borland-delphi/browse_thread/thread/fdc16d03b613a00e

    【讨论】:

    • 我会看一下链接,这样我就可以知道了,但是,我正在为 iPhone 做这个。
    • 比较的是文件系统与 sqlite blob。我认为它可以翻译。让你放慢速度的事情(存储带有关系写入和读取的 blob)在 sqlite 中,这对所有平台都很常见——尤其是那些像设备一样内存受限的平台。
    猜你喜欢
    • 2013-03-21
    • 2020-07-25
    • 2015-05-28
    • 2018-01-14
    • 2016-11-28
    • 1970-01-01
    • 1970-01-01
    • 2017-03-14
    • 1970-01-01
    相关资源
    最近更新 更多