The Unicode2Str function in MySQLdb/converters.py isn't usable as is since it fails to escape and quote the encoded string. This results in the bare text being interpolated into the SQL. If the text is a single word it is likely to result in an exception such as
OperationalError: (1054, Unknown column 'param_value' in 'where clause')
Ignoring questions about the correct encoding to use and how this should interact with the charset setting it seems to me the default Unicode2Str should do one of two things:
1) raise a NotImplementedError('you must provide a unicode conversion function'), or
2) do the intuitive thing:
def Unicode2Str(s, d):
return string_literal(s.encode('utf8'), d)
Log in to post a comment.