【发布时间】:2017-06-08 04:16:56
【问题描述】:
当我使用这个子句时,一切都是正确的。 find 这里是モンキー・D・ルフィ
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, "您的 SQL 语法有错误;请查看与您的 MySQL 服务器版本相对应的手册,了解在 ''(\'\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\')''第 1 行") 对于这个子句,发生了错误。
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)
对于这个子句,一切都很顺利。 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 表示它是一组字符串,而不仅仅是单个字符串。
【问题讨论】:
-
miss "" around String ~> 很多是" some text"
-
@NamNguyễn 你的意思是把
(モンキー・D・ルフィ)改成("モンキー・D・ルフィ")? -
你试过 find.encode('utf-8') 吗?
-
@Tiny.D 我试过了,同样的错误。
-
您在此处找到的字符串类似于
"(モンキー・D・ルフィ) or ('モンキー・D・ルフィ')"?