I am working on a recipe based app. Here on clicking a recipe name I am displaying a detailed view with things like ingredient,skill, time etc and instruction link. On clicking the instruction I need to show a series of images.
My question is what would be the right way to store these images - in sqlite itself or in folder and the name of folder in the db.
I plan to store the data for detailed view in sqlite; assuming there are say 50 recipes is it wise to read all the recipes data at app load time or only the particular recipe data on row selection. I am little bit confused weather extra sql call would make the app slower in second case.
Thanks for all the help.
regards,
Rols
edit: the app is read-only, user won't be adding new entries.
Last edited by rollinggem; 11-28-2010 at 08:07 AM.
Reason: adding extra information
I am working on a recipe based app. Here on clicking a recipe name I am displaying a detailed view with things like ingredient,skill, time etc and instruction link. On clicking the instruction I need to show a series of images.
My question is what would be the right way to store these images - in sqlite itself or in folder and the name of folder in the db.
I plan to store the data for detailed view in sqlite; assuming there are say 50 recipes is it wise to read all the recipes data at app load time or only the particular recipe data on row selection. I am little bit confused weather extra sql call would make the app slower in second case.
Thanks for all the help.
regards,
Rols
edit: the app is read-only, user won't be adding new entries.
Everything I've read advises against storing big blocks of binary data in SQLite. It slows things down. Better to store a path in your database, and save the images to your documents directory. Then use the path to load the images when you need them. That's what I've done, and it works well.
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.
For portability to other systems (non-iOS...), consider keeping in all in a database. I have a 20+ MB sqlite3 READ-ONLY SQLite3 database with over 500 images, that are accessed with bulk queries about 20-40 images at a time. All images as stored as BLOBs... I initially started it as holding 10-20 images, and later scaled it up to it's current size, and never ran into 'new' performance issues. I do run into problems loading multiple (10+) images at a time, mainly on an iPhone 3G (iPad and iPhone 4 have some lag for large query-retrieve but there are tricks to get around that...), but if you are querying 1 or 2 images at a time, sql will be a really good way to go - still not as fast as keeping in your resource folder though... I do not know how performance will change if you make it read-write...
As an aside, I use the same SQL db to hold tableViewCell images, and they load without lag on a 3G (using the standard 'recycled' tableview cells...).
@Duncan: thanks a lot for quick reply.
@JDave: thanks for sharing the db information, your numbers gave me good idea of what to expect from the sqlite db. My use case is very much in line with what you mentioned, around 500 images with loading of 15-20 images at a time. For now I am just going to put them in file system mainly because I would prefer not to have a lag.