0

I am making an iPhone app where in I want to make an image - quiz based app. The app will ask questions based on the image. Hence I want to insert images in my sqlite3 database from the terminal, which I will then add to my Xcode project.

I created the database on the terminal and now I want to insert jpg images (located on my desktop) to my table. How do I add them? Do I need to add the path.

Also , is it a feasible to add about 150 images to the database and then load the table in Xcode? I am just learning iPhone development and do not wish to to it in App Store.

user1048396
  • 123
  • 1
  • 4
  • 10

3 Answers3

0

hi. you can store the image in resource folder with the help of image picker controller and then just store it name in database . and with the help of following code you can get the image location and easily fetch in project.

 NSString *strpath=[[NSBundle mainBundle] pathForResource:@"imagename" ofType:@"jpg"];

And yes you can display number of images in tableview but if you will use lazy loading for display images in table view than it would be great. here us the link for download source code Click Here

AJPatel
  • 2,291
  • 23
  • 42
Kartik
  • 779
  • 7
  • 22
0

You can save the image in the sqlite database in form of NSData of image.

UIImage *img = [UIImage imageWithContentsOfFile:ImageFilePath];

NSData *imageData = UIImagePNGRepresentation(img);

Save imageData in sqlite database.

I will also suggest you to compress(gzip) the NSData of the UIImage before storing it, if you want to save large number of images.

Anil Kothari
  • 7,653
  • 4
  • 20
  • 25
  • check this link as your solution to the problem accessing the database from the xcode.............. http://stackoverflow.com/questions/8178011/how-to-insert-only-one-username-and-password-in-sqlite-database/8178682#8178682 – Anil Kothari Dec 03 '11 at 10:10
0

You can use SQLite Manager or Mozila SQLite Plugin(Google it). There you can add column for the image in your table of BLOB data type. Here you can easily add image. This is the best way as far i can tell you.

makboney
  • 1,808
  • 1
  • 17
  • 34
  • I made a table and inserted values in it through the terminal. When I select the values, I do find the values as well. But when I drag-drop it and copy it in Xcode4 and run a select query it states the table doesn't exist. Can you please guide me on this error? – user1048396 Dec 03 '11 at 08:34
  • why you are not going for a new one? – makboney Dec 03 '11 at 08:38