2006年07月12日 星期三 19:00
145行:
charset = db.character_set_name()
query = query.encode(charset)
而此时获得的
charset并不是mysql的当前缺省字符集,无论是直接修改my.ini还是在连接的时候指定charset='utf8'都不行!有哪位同学遇到过这个情况?谢谢!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060712/7d42aea5/attachment.html
2006年07月13日 星期四 09:05
On 7/12/06, wang yingqi <wangyingqi at gmail.com> wrote: > > 145行: > charset = db.character_set_name() > query = query.encode(charset) > 而此时获得的charset并不是mysql的当前缺省字符集,无论是直接修改my.ini还是在连接的时候指定charset='utf8'都不行!有哪位同学遇到过这个情况?谢谢! > 好象要执行一个set names 'gb2312'之类的命令就行了。不需要这样转换吧。 -- I like python! My Blog: http://www.donews.net/limodou My Django Site: http://www.djangocn.org NewEdit Maillist: http://groups.google.com/group/NewEdit
2006年07月13日 星期四 16:43
不行的!
而且这行代码是MySQLdb里面的,由于这个原因导致有中文的查询会出问题。
今天在MySQLdb的主页上找到了作者的解答,
通过execute的第二个参数,将字符串当作一个ascii数据来传递就可以了,
sql = 'select * from table where name = %s'
c.execute(sql, ("中文",))
作者的解答在这
http://sourceforge.net/forum/forum.php?thread_id=1467703&forum;_id=70460
On 7/13/06, limodou <limodou at gmail.com> wrote:
>
> On 7/12/06, wang yingqi <wangyingqi at gmail.com> wrote:
> >
> > 145行:
> > charset = db.character_set_name()
> > query = query.encode(charset)
> >
> 而此时获得的charset并不是mysql的当前缺省字符集,无论是直接修改my.ini还是在连接的时候指定charset='utf8'都不行!有哪位同学遇到过这个情况?谢谢!
> >
> 好象要执行一个set names 'gb2312'之类的命令就行了。不需要这样转换吧。
> --
> I like python!
> My Blog: http://www.donews.net/limodou
> My Django Site: http://www.djangocn.org
> NewEdit Maillist: http://groups.google.com/group/NewEdit
>
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060713/bf439931/attachment-0001.html
Zeuux © 2025
京ICP备05028076号