[英]how do I query an unicode string in sqlite3, using Python
假设我有一个Unicode字符串u"Robinson Can\ó"
,并且使用以下命令将该字符串存储在sqlite3数据库中:
cursor.execute('create table tb (name text)')
cursor.execute('insert into tb values (?)', str')
但是,如果我想从数据库中查询unicode字符串u“ Robinson Can \\ u00f3”,我什么也没得到。
cursor.execute("select * from tb where name = '%s'" % str)
但是,如果我查询另一个不包含unicode的unicode字符串,例如u“ Kobe Byrant”,我可以找回输入。
那么谁能告诉我如何使用Python使用sqlite3处理unicode?
非常感谢!
执行SQL代码时, 不要使用字符串插值。 改用SQL参数:
cursor.execute("select * from tb where name = ?", (str,))
这适用于涉及参数的任何数据库交互,而不仅限于SQLLite。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.