title: How do I check if an insert was successful with MySQLdb in Python?
body: <p>I have this code:</p>
  
  <pre><code>cursor = conn.cursor()
  cursor.execute(("insert into new_files (videos_id, filename, "
                  "is_processing) values (%s,%s,1)"), (id, filename))
  logging.warn("%d", cursor.rowcount)
  if (cursor.rowcount == 1):
      logging.info("inserted values %d, %s", id, filename)
  else:
      logging.warn("failed to insert values %d, %s", id, filename)
  cursor.close()
  </code></pre>
  
  <p>Fun as it is, <code>cursor.rowcount</code> is <em>always</em> one, even though i updated my database to make the videos_id a unique key. That is, the  insert fails because in my tests the same <code>videos_id</code> is going to appear (and when I check the database, nothing was inserted).
  But for whatever reason, the <code>rowcount</code> is always 1 - even the <code>logging.warn</code> I have spits out a <code>rowcount</code> of 1. </p>
  
  <p>So, the question:<br/>
  Can I use <code>rowcount</code> to work out if an insert went fine? If so, what am I (presumably) doing wrong?
  otherwise, how do i check if an insert went fine?</p>