SQL lite: text and image question

0 views
Skip to first unread message

Patrick Kedziora

unread,
Mar 23, 2009, 4:37:07 PM3/23/09
to iphonesdkd...@googlegroups.com
Hi,

I want to display questions and solutions that have text and images and want to store them in a SQL lite database. What is the best way to do this?

Thanks,
Patrick

--
_________________________
Patrick G. Kedziora

Senior Managing Director
Growth Advisors Inc.

USA Cell: 305.788.1696
INTL Cell: (33) 6-10-69-40-63
SKYPE: pkedziora

e1: patrick....@gmail.com
e2: pat...@growthadvisorsinc.com
i:  http://www.growthadvisorsinc.com

"UNCERTAINTY requires a GROWTH plan"

Gregory Seidman

unread,
Mar 23, 2009, 8:26:50 PM3/23/09
to iphonesdkd...@googlegroups.com
On Mon, Mar 23, 2009 at 04:37:07PM -0400, Patrick Kedziora wrote:
> I want to display questions and solutions that have text and images and want
> to store them in a SQL lite database. What is the best way to do this?

You almost certainly do not want to store images in the database when you
have access to a filesystem. If you have all the text and images a priori
(i.e. they are to be shipped in the app bundle), just store the names of
the images and use [UIImage imageNamed:]. If you are retrieving them from
the web or getting them from the user, I recommend using
UIImagePNGRepresentation() and storing it with a GUID for the filename
under the ~/Documents directory, then saving that name in the database. You
can retrieve it with [UIImage imageWithContentsOfFile:].

Of course, there is no problem with storing text in SQLite.

> Thanks,
> Patrick
--Greg

Brad Larson

unread,
Mar 25, 2009, 9:44:34 AM3/25/09
to iPhone SDK Development
On Mar 23, 7:26 pm, Gregory Seidman <gsslist
+iphone...@anthropohedron.net> wrote:
> On Mon, Mar 23, 2009 at 04:37:07PM -0400, Patrick Kedziora wrote:
> > I want to display questions and solutions that have text and images and want
> > to store them in a SQL lite database. What is the best way to do this?
>
> You almost certainly do not want to store images in the database when you
> have access to a filesystem. If you have all the text and images a priori
> (i.e. they are to be shipped in the app bundle), just store the names of
> the images and use [UIImage imageNamed:]. If you are retrieving them from
> the web or getting them from the user, I recommend using
> UIImagePNGRepresentation() and storing it with a GUID for the filename
> under the ~/Documents directory, then saving that name in the database. You
> can retrieve it with [UIImage imageWithContentsOfFile:].
>

There are certain situations where it might be advantageous to store
images within the SQLite database, so that you only have to manage a
single file, rather than multiple ones across a filesystem. I provide
an example of saving a PNG representation of an image in SQLite as a
binary BLOB on Stack Overflow:

http://stackoverflow.com/questions/643682/reading-and-writing-images-to-an-sqlite-db-for-iphone-use/643819#643819

Personally, I use this to store small (~2kb) image thumbnails
alongside equations that I provide in a preloaded data SQLite database
within my application. It makes it easy to copy across the entire
database from the Mac, where I create it, to the iPhone application,
where it's used.

______________________
Brad Larson, Ph.D.
Sunset Lake Software
http://www.sunsetlakesoftware.com
Reply all
Reply to author
Forward
0 new messages