title: Escaping characters for MySQL for UPDATE operation using Python/MySQLdb
body: <p><strong>Note:</strong> I have discovered that re.escape(string) will do escaping but man, does it escape a lot. I can use that if I have to, but I am leaving the question open for any other ideas, also in case this is stumbled upon in the future.</p>
  
  <p>I found a great S.O. answer here regarding INSERTing data into MySQL with Python ( I'm using 2.7 ) where the data contains apostrophes : <a href="https://stackoverflow.com/questions/12902862/python-mysql-escaping-quotes">Python mySQL - escaping quotes</a></p>
  
  <p>In a nutshell, the S.O. answer was to do this.....</p>
  
  <pre><code>sql = "INSERT INTO TABLE_A(COL_A,COL_B) VALUES(%s, %s)"
  a_cursor.execute(sql, (val1, val2))
  </code></pre>
  
  <p>I need to do this for an UPDATE though. My current method is ....</p>
  
  <pre><code>sql = "UPDATE table SET COL_A='R', COL_B='%s', COL_C='%s', COL_D='%s', COL_E='%s',COL_F='%s' WHERE COL_G='%s'" % (val1, val2, val3, val4, val5, val6)
  cur.execute(sql)
  </code></pre>
  
  <p>Error I get is: 1064 error in syntax. </p>
  
  <p>The problem is val5, it's a blob of text that contains apostrophes ( and who knows what else ) and I need a way to escape special characters before UPDATE. I have sneaking suspicion that I'll just have to do this massive routine where I have to specifically spell out characters as I tend to find them but I'd like to see if anyone else has had this issue.</p>
  
  <p>I appreciate any pointers in the right direction.</p>