この句を使用すると、すべて正しいです。ここでfind
はモンキー・D・ルフィ
Python Django mysqldbでユニコード値を選択
sql_fmt = "select name, gender, age, height, hobby, ability, popularity, voice_actor, birth_place, image from characters where name in ('%s');" % find.encode('utf-8')
self.db.execute(sql_fmt)
あるしかし、私はこの句を使用する場合、エラーが起こりました。ここでfind
が(モンキー・D・ルフィ)
または('モンキー・D・ルフィ')
sql_fmt = "select name, gender, age, height, hobby, ability, popularity, voice_actor, birth_place, image from characters where name in %s;"
self.db.execute(sql_fmt, find)
エラーです:
ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''(\'\xe3\x83\xa2\xe3\x83\xb3\xe3\x82\xad\xe3\x83\xbc\xe3\x83\xbbD\xe3\x83\xbb\xe3\x83\xab\xe3\x83\x95\xe3\x82\xa3\')'' at line 1") And for this clause, error happened.
find
here isモンキー・D・ルフィ
.
sql_fmt = "select name, gender, age, height, hobby, ability, popularity, voice_actor, birth_place, image from characters where name in ('%s');"
self.db.execute(sql_fmt, find)
そして、この句のため、すべてがうまくいきます。 find
はモンキー・D・ルフィ
です。
sql_fmt = "select name, gender, age, height, hobby, ability, popularity, voice_actor, birth_place, image from characters where name in (%s);"
self.db.execute(sql_fmt, find)
注:
私はin
を使用し、それが文字列の集合ではなく、単に1つの文字列であることを意味します。
ミス "" 文字列の周りに〜>多くのことが "テキスト" NamNguyễ[email protected] –
あなたは 'の変化を意味する(モンキー・D・ルフィ)'( 'への「モンキー・D・ルフィ ")'? – Howard
find.encode( 'utf-8')を試してみましたか? –