title: Storing and retrieving zip files in SQLite gives "Could not decode to UTF-8"
body: <p>I have a table in SQLite 3 as follows and I am planning on using it to store a variety of files: txt, pdf, images and zip files.</p>
  <pre class="lang-sql prettyprint-override"><code>CREATE TABLE zip (filename TEXT PRIMARYKEY NOT NULL, zipfile BLOB NOT NULL);
  </code></pre>
  <p>To store and retrieve I am experimenting with the following python code</p>
  <pre class="lang-py prettyprint-override"><code>#!env/bin/python
  
  
  import sqlite3 as lite
  import os
  import sys
  
  def insertfile(_filename):
      try:
          con = lite.connect('histogram.db', detect_types=lite.PARSE_DECLTYPES)
          con.row_factory = lite.Row
          cur = con.cursor()
          cur.execute('PRAGMA foreign_keys=ON;')
          _f = open(_filename,'rb')
          _split = os.path.split(_filename)
          _file = _split[1]
          _blob = _f.read()
          cur.execute('INSERT INTO zip (filename,zipfile) VALUES (?,?)', (_file,lite.Binary(_blob)))
          _f.close()
          con.commit()
          cur.close()
          con.close()
      except Exception as ex:
          print ex
  
  def getfile(_filename):
      try:
          con = lite.connect('histogram.db', detect_types=lite.PARSE_DECLTYPES)
          con.row_factory = lite.Row
          cur = con.cursor()
          cur.execute('PRAGMA foreign_keys=ON;')
          cur.execute('SELECT zipfile from zip where filename = ?', (_filename,))
          _files = cur.fetchall()
          if len(_files) &gt; 0:
              _file  = open('Test/'+ _filename,'wb')
              _file.write(_files[0]['zipfile'])
              _file.close()
          cur.close()
          con.close()
      except Exception as ex:
          print ex
  
  if __name__ == '__main__':
      print 'works'
      insertfile(sys.argv[1])
      getfile(os.path.split(sys.argv[1])[1])
  </code></pre>
  <p>When I test this on files like <code>.txt</code>, <code>.py</code>, <code>.pdf</code> etc., it works fine.</p>
  <p>With Zip files, there is no error while storing into the table but an error while retrieving the file:</p>
  <blockquote>
  <p>Could not decode to UTF-8 column 'zipfile' with text 'PK '</p>
  </blockquote>
  <p>There seems to be some encoding or decoding issue.</p>