[英]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.