我有代表不同语言用户名的数据。我执行了如下适当的unicoding过程:
while attempts < 3 and not success:
query = ur'''select gu_name from globaluser where gu_name = "{uname}"'''.format(uname=unicode(filerow['user_name'],'utf-8', errors='strict'))
try:
self.gdbCursor.execute(query.encode('utf-8'))
gUser = self.gdbCursor.fetchone()
但当谈到这样的名字时,Name1_"GG"_Name1AnotherName
我最后得到了以下错误:
ProgrammingError: (1064, 'You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near
\'GG" Cooper"\'
在第1行')
如何正确编码这些类型的字符?在
更新:
根据提供的答案,我做了以下工作:
\'GG" Cooper"\'
解析用户名
但我仍然得到以下错误:
ProgrammingError: (1064, 'You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near \'GG" Cooper"\' at line 1')
您应该按照以下建议使用参数输入:
http://legacy.python.org/dev/peps/pep-0249/#id15
下面是一个例子:
相关问题 更多 >
编程相关推荐