如何在sqlite3中插入中文字符

2024-12-02 12:45:31
推荐回答(1个)
回答(1):

第一种,设置text_factory = str
def insert():
users = ('腾讯qq', 'qq@example.com')
conn = sqlite3.connect(dbname)
conn.text_factory = str ##!!!
cursor = conn.cursor()
cursor.execute("insert into userinfo(name, email) values(?, ?)", users)
conn.commit()
cursor.close()
conn.close()
http://my.oschina.net/letiantian/blog/217770