【发布时间】:2011-11-02 02:51:22
【问题描述】:
我用的是 MySQLdb,我用的是:
cursor.execute(QUERY)
QYERY 在哪里:
INSERT (A,B,C) VALUES("%s","%s",something);'%(k1, u'W')**
w 是一个波斯字母(字面意思是!我只是将它替换为 W,以防您在查看波斯字母时遇到问题,它类似于 ب),并且 k1 是英文。但我明白了:
`Traceback (most recent call last):
File "./i.py", line 47, in <module>
c.doit(db)
File "./i.py", line 41, in doit
db.cr.execute('INSERT (A,B,C) VALUES("%s","%s",something);'%(k1, u'ب'))
File "/usr/lib/pymodules/python2.7/MySQLdb/cursors.py", line 174, in execute
self.errorhandler(self, exc, value)
File "/usr/lib/pymodules/python2.7/MySQLdb/connections.py", line 36, in defaulterrorhandler
raise errorclass, errorvalue
_mysql_exceptions.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 \'(term_tit,term_desc,term_cat) VALUES("a\n","\xd8\xa8",general)\' at line 1')`
看到了吗? W字母变成“\xd8\xa8”怎么办?
更新:sql查询错误已修复,但\xd8\xa8问题依然存在, 现在从数据库中检索数据时,我得到“??????”而不是我输入的内容
【问题讨论】:
标签: python unicode mysql-python