title: How to store and retrieve NSData picture in SQLite?
body: <p>I am trying to figure out how to save and load <code>NSData</code> (happens to be <code>UIImages</code>) into SQLite.  Should I create the table with TEXT or BLOB columns to store it?  Then, what are some code examples for saving and retrieving?</p>
  
  <p>For example, I have classes that persist using a <code>.save()</code> method; in the <code>.save()</code> method, it simply performs <code>sqlite3_exec</code> on a SQL string to do an <code>INSERT</code>.  That's great for basic data types, but <code>NSData</code>?  Should I use TEXT and UTF8 to encode/decode?  If so, then here's what I have to save:</p>
  
  <pre><code>...
  let sqlTEXT = "INSERT INTO mytable (photo) VALUES ('\(picData.base64EncodedStringithOptions(NSDataBase64EncodingOptions.Encoding64CharacterLineLength))')"
  if (sqlite3_exec(db, sqlText, nil, nil, nil) == SQLITE_OK {
      // fine
  } else {
      // handle error
  }
  </code></pre>
  
  <p>And, to read:</p>
  
  <pre><code>...
  let picEncoding = String(sqlite3_column_text(fromRecord, 0))
  let picData = NSData(base64EncodedString: pic, options: NSDataBase64DecodingOptions.IgnoreUnknownCharacters)
  </code></pre>
  
  <p>Does that seem right?</p>