I am currently using mysqldb.
What is the correct way to avoid strings in mysqldb arguments?
Please note that E = lambda x: x.encode('utf-8') 1), so my connection is established with charset = 'utf8'.
These are the errors I get for these arguments: w1, w2 = u'δ½ ε₯½', u'ζε₯½'
self.cur.execute("SELECT dist FROM distance WHERE w1=? AND w2=?", (E(w1), E(w2))) ret = self.cur.execute("SELECT dist FROM distance WHERE w1=? AND w2=?", (E(w1), E(w2)))
File "build / bdist.linux-i686 / egg / MySQLdb / cursors.py", line 158, executed by TypeError: not all arguments converted during string formatting
self.cur.execute("SELECT dist FROM distance WHERE w1=%s AND w2=%s", (E(w1), E(w2)))
This works fine, but when w1 or w2 have \ inward, then dumping obviously failed.
I personally know that% s is not a good way to pass arguments due to injection attacks, etc.
source share