title: Store images in to sqlite database
body: <p>I know this question was asked by many people and there are several discussions and arguments on "Why to use sqlite,use FMDB,core data" etc.. to store or insert images in database.But please do understand my problem that I am very much used to sqlite3 and I am unable to go with core data or some other db.Also I am just in learning stages of iphone technology.So I request to please provide me a solution that can be dealt with sqlite only ;)</p>
  
  <p>Apologies if any wrong in my request!</p>
  
  <p>I have a text field that will show table with suggestions when a letter is typed,i.e. from contacts,say if I type letter "L" ,"Lakshaman Rao,Prasanna Lakshmi,"Lokesh Sharan" etc..</p>
  
  <p>Now I am trying to get the corresponding contact picture from the respective contact.So I have searched for code sample on how to retrieve contact images and implemented the following way:</p>
  
  <pre><code>NSData *imgData = nil;
  imgData = (NSData *)ABPersonCopyImageData(ref);
  contactImage = [UIImage imageWithData:imgData]; 
  </code></pre>
  
  <p>Now I have searched for similar kind of questions <a href="https://stackoverflow.com/questions/2037432/saving-image-to-documents-directory-and-retrieving-for-email-attachment">here</a> and <a href="https://stackoverflow.com/questions/9479293/how-to-insert-image-in-sqlite-database-in-iphone">there</a> and the common answer was to save the image in documents directory of the app and in the db save only the path of the image.</p>
  
  <p>As inserting in blobs in db will make our db very very slow :(</p>
  
  <p>But how do I do this.I am unable to understand the code snippet in the links I have gone through properly,how do I convert the contactImage which is of UIImage type to NSString so that,I can insert the string to database table holding a record as VARCHAR type!</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>This is the code suggested there:</p>
  
  <pre><code>NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,     NSUserDomainMask, YES);
  NSString *documentsDirectory = [paths objectAtIndex:0];
  NSString *getImagePath = [documentsDirectory stringByAppendingPathComponent:@"savedImage.png"];
  UIImage *img = [UIImage imageWithContentsOfFile:getImagePath];
  </code></pre>
  
  <p>This is code I implemented:</p>
  
  <pre><code>ABAddressBookRef addressBook = ABAddressBookCreate( );
  CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople( addressBook );
  CFIndex nPeople = ABAddressBookGetPersonCount( addressBook );
  
   NSString *contactFirstName = nil;
   NSString *contactLastName = nil;
   NSString *fullName = nil;
  
      for ( int i = 0; i &lt; nPeople; i++ )
      {
          ref = CFArrayGetValueAtIndex( allPeople, i );
          contactFirstName = [[[NSString alloc] initWithString:(NSString *)ABRecordCopyValue(ref, kABPersonFirstNameProperty)]autorelease];
          contactLastName = [[[NSString alloc] initWithString:(NSString *)ABRecordCopyValue(ref, kABPersonLastNameProperty)]autorelease];
  
          contactLastName = [NSString stringWithFormat:@" %@",contactLastName];
          fullName = [contactFirstName stringByAppendingString:contactLastName];
  
          [contactList addObject:fullName];
  }
  
      NSData *imgData = nil;
      imgData = (NSData *)ABPersonCopyImageData(ref);
      contactImage = [UIImage imageWithData:imgData];  
  
      CFRelease(allPeople);
      CFRelease(addressBook);
  </code></pre>
  
  <p>Please help me out,Struggling very badly on how to deal and move on with this :(</p>
  
  <p>Thanks all in advance :)</p>