8 Jan
2014
8 Jan
'14
10:34 a.m.
On Wed, 8 Jan 2014 09:50:30 +0900
INADA Naoki
textdata = b"hello"
textdata shouldn't be a bytes object! If it's text it's a str.
bindata = b"abc\xff\x00" query = "UPDATE table SET textcol=%s bincol=%s"
print build_query(query, textdata, bindata)
I can't port this to Python 3.
I'm sure you can port it. Just decode your bindata using surrogateescape: bindata = bindata.decode('utf8', 'surrogateescape') and then encode the query at the end: query = query.encode('utf8', 'surrogateescape') It will be a little slower, though. Regards Antoine