title: How Can I Save & Retrieve an image (bytes) to SQLite (blob) using FMDB?
body: <p>I'm making an iOS App that need to show some images from a remote site (from an URL), and everytime the users enter to the screen that should show the image, the app get freeze until the download is completed. So I want to store the images already downloaded into a SQLite Table named COVERS. </p>
  
  <p>Here is the code that how I'm downloading and Showing the image:</p>
  
  <p>Suppose that movieCover is an <strong>UIImageView</strong> and the object movie has a <strong>NSURL</strong> property named cover that contains the URL of the image to be downloaded.</p>
  
  <pre><code>NSData *cover = [[NSData alloc] initWithContentsOfURL:movie.cover];
  movieCover.image = [[UIImage alloc] initWithData:cover];
  </code></pre>
  
  <p>But, I want to change it to something like this:</p>
  
  <pre><code>NSData *cover = [appDelegate.dataBase getCoverForMovie:movie];
  if( !cover ) {
      cover = [[NSData alloc] initWithContentsOfURL:movie.cover];
      [appDelegate.dataBase setCover:cover ToMovie:movie];
  }
  
  movieCover.image = [[UIImage alloc] initWithData:cover];
  </code></pre>
  
  <p>Suppose that appDelegate is a property of the current ViewController, and dataBase is a property of the AppDelegate wich uses FMDB to manipulate the data in the DataBase.</p>
  
  <p>I need to get the cover previously saved in the database using the method:</p>
  
  <pre><code>- (NSData *)getCoverForMovie:(Movie *)movie;
  </code></pre>
  
  <p>But, if there is not a cover saved, then return nil.</p>
  
  <p>So I need to save the cover using the method </p>
  
  <pre><code>- (BOOL)saveCover:(NSData *)cover ForMovie:(Movie *)movie;
  </code></pre>
  
  <p>But I don't know how to code this method. Need some help with it.</p>