title: python inserting and retrieving binary data into mysql
body: <p>I'm using the MySQLdb package for interacting with MySQL. I'm having trouble getting the proper type conversions.</p>
  
  <p>I am using a 16-byte binary uuid as a primary key for the table and have a mediumblob holding zlib compressed json information.</p>
  
  <p>I'm using the following schema:</p>
  
  <pre><code>CREATE TABLE repositories (
      added_id int auto_increment not null,
      id binary(16) not null,
      data mediumblob not null,
      create_date int not null,
      update_date int not null,
      PRIMARY KEY (added_id),
      UNIQUE(id)
  ) DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ENGINE=InnoDB;
  </code></pre>
  
  <p>Then I create a new row in the table using the following code:</p>
  
  <pre><code>data = zlib.compress(json.dumps({'hello':'how are you :D'})
  row_id = uuid.uuid(4).hex
  added_id = cursor.execute('
      INSERT INTO repositories (id, data, create_date, update_date) 
      VALUES (%s, %s, %s, %s)',
      binascii.a2b_hex(row_id), 
      data, 
      time.time(), 
      time.time()
  )
  </code></pre>
  
  <p>Then to retrieve data I use a similar query:</p>
  
  <pre><code>query = cursor.execute('SELECT added_id, id, data, create_date, update_date ' \
      'FROM repositories WHERE id = %s',
      binascii.a2b_hex(row_id)
  )
  </code></pre>
  
  <p>Then the query returns an empty result.</p>
  
  <p>Any help would be appreciated. Also, as an aside, is it better to store unix epoch dates as integers or TIMESTAMP?</p>
  
  <p><strong>NOTE:</strong> I am not having problems inserting the data, just trying to retrieve it from the database. The row exists when I check via mysqlclient.</p>
  
  <p>Thanks Alot!@</p>