def _py2sql(self, val):
r"""
Work around a couple of problems in SQLite that maybe pysqlite
should take care of: give it True and False and it thinks
they're column names; give it Unicode and it tries to insert
it in, possibly, ASCII.
>>> meth = SqliteDB(db='nonexistent')._py2sql
>>> [meth(x) for x in [True, False, 1, 2, 'foo', u'souffl\xe9']]
[1, 0, 1, 2, 'foo', 'souffl\xc3\xa9']
"""
if val is True: return 1
elif val is False: return 0
elif isinstance(val, unicode): return val.encode(self.encoding)
else: return val
评论列表
文章目录