2006年09月13日 星期三 14:14
有人用过MySQLdb么,python连接mysql。 我无法执行包含中文的sql语句,求高手赐教 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://python.cn/pipermail/python-chinese/attachments/20060913/28df7546/attachment.html
2006年09月13日 星期三 14:19
On 9/13/06, 曹翔 <caoxiang在tomonline-inc.com> wrote: > > > > > 有人用过MySQLdb么,python连接mysql。 > > 我无法执行包含中文的sql语句,求高手赐教 中文只要使用变量嵌入,Python 会以Unicode 字串提交的,一般不用特别处理 不过有大量中文时,我是直接处理为utf8 或是 编码为 url 安全的字串提交的 > > > > > _______________________________________________ > python-chinese > Post: send python-chinese在lists.python.cn > Subscribe: send subscribe to > python-chinese-request在lists.python.cn > Unsubscribe: send unsubscribe to > python-chinese-request在lists.python.cn > Detail Info: > http://python.cn/mailman/listinfo/python-chinese > -- """Time is unimportant, only life important! blogging : http://blog.zoomquiet.org/pyblosxom/ wiki enter: http://wiki.woodpecker.org.cn/moin/ZoomQuiet in douban: http://www.douban.com/people/zoomq/ """
2006年09月13日 星期三 14:35
>> 有人用过MySQLdb么,python连接mysql。 >> >> 我无法执行包含中文的sql语句,求高手赐教 >中文只要使用变量嵌入,Python 会以Unicode 字串提交的,一般不用特别处理 >不过有大量中文时,我是直接处理为utf8 或是 编码为 url 安全的字串提交的 能否给段代码例子,谢谢
2006年09月13日 星期三 20:53
ÛM:ÿßõÝÆ¨Æ&§Ú&¢ybè§qÊ&3$-ÖéÊØhl¬ª[*üÔ'(uëË«Ü)Þ±ãè²ÛÚr¶'r§zÇ¥Ël§+a¢w'Jæìr¸zǧv˱Êâmëh§+a¢w!w¬z·ª¹ë-+-²ÜIì¹»®&Þ±éݺ{.nÇ+·¢Ü)Þ±êު笶X¬¶Êr¶'rpÞµ¨¥"wèÛiÿúr¶'ræj)fjåËbú?§+a¢w!w¬zm§ÿððÊç(ùÞÆÚZ®Ú´®dÃæ°Îæü宪
2006年09月13日 星期三 23:54
测试回复 On 9/13/06, 谢小漫 <cat在ewyu.com> wrote: > > == > 待会儿发。 > > > 2006/9/13, 曹翔 <caoxiang在tomonline-inc.com>: > > >> 有人用过MySQLdb么,python连接mysql。 > > >> > > >> 我无法执行包含中文的sql语句,求高手赐教 > > >中文只要使用变量嵌入,Python 会以Unicode 字串提交的,一般不用特别处理 > > > > >不过有大量中文时,我是直接处理为utf8 或是 编码为 url 安全的字串提交的 > > > > 能否给段代码例子,谢谢 > > _______________________________________________ > > python-chinese > > Post: send python-chinese在lists.python.cn > > Subscribe: send subscribe to > python-chinese-request在lists.python.cn > > Unsubscribe: send unsubscribe to > python-chinese-request在lists.python.cn > > Detail Info: > http://python.cn/mailman/listinfo/python-chinese > > > > > -- > 花开邑大,漫步心月湖。 > http://www.ewyu.com/ > _______________________________________________ > python-chinese > Post: send python-chinese在lists.python.cn > Subscribe: send subscribe to > python-chinese-request在lists.python.cn > Unsubscribe: send unsubscribe to > python-chinese-request在lists.python.cn > Detail Info: > http://python.cn/mailman/listinfo/python-chinese > -- Yours, fluke fluke在sfcube.net http://blog.ospattern.net
2006年09月14日 星期四 08:56
rç3$-ÖÜ¢yÞr×[+¬zºè¢ÚZ²Ì.±ë§Ê{W!j»¶ë_ñË«²
2006年09月14日 星期四 09:10
谢小漫 写道:
>
> conn = MySQLdb.connect(db="my",user="root",
> passwd="ggg",use_unicode=1, charset='utf8')
> cursor = conn.cursor()
> query = "insert into ewyu(gg,ff) values(%s , %s)"
>
> para = ("中国","北京")
> cursor.execute(query)
> conn.commit()
> conn.close()
>
>
>
应该是cursor.execute(query,para)吧
> 用的是utf8
>
>
> 2006/9/13, Fluke <fluke.l在gmail.com fluke.l在gmail.com>>:
>
> 测试回复
> On 9/13/06, 谢小漫 <cat在ewyu.com cat在ewyu.com>> wrote:
> >
> > ==
> > 待会儿发。
> >
> >
> > 2006/9/13, 曹翔 <caoxiang在tomonline-inc.com
> caoxiang在tomonline-inc.com>>:
> > > >> 有人用过MySQLdb么,python连接mysql。
> > > >>
> > > >> 我无法执行包含中文的sql语句,求高手赐教
> > > >中文只要使用变量嵌入,Python 会以Unicode 字串提交的,一般不用
> 特别处理
> > >
> > > >不过有大量中文时,我是直接处理为utf8 或是 编码为 url 安全的字
> 串提交的
> > >
> > > 能否给段代码例子,谢谢
> > > _______________________________________________
> > > python-chinese
> > > Post: send python-chinese在lists.python.cn
> python-chinese在lists.python.cn>
> > > Subscribe: send subscribe to
> > python-chinese-request在lists.python.cn
> python-chinese-request在lists.python.cn>
> > > Unsubscribe: send unsubscribe to
> > python-chinese-request在lists.python.cn
> python-chinese-request在lists.python.cn>
> > > Detail Info:
> > http://python.cn/mailman/listinfo/python-chinese
> >
> >
> >
> >
> > --
> > 花开邑大,漫步心月湖。
> > http://www.ewyu.com/
> > _______________________________________________
> > python-chinese
> > Post: send python-chinese在lists.python.cn
> python-chinese在lists.python.cn>
> > Subscribe: send subscribe to
> > python-chinese-request在lists.python.cn
> python-chinese-request在lists.python.cn>
> > Unsubscribe: send unsubscribe to
> > python-chinese-request在lists.python.cn
> python-chinese-request在lists.python.cn>
> > Detail Info:
> > http://python.cn/mailman/listinfo/python-chinese
> >
>
>
> --
> Yours,
> fluke
> fluke在sfcube.net fluke在sfcube.net>
> http://blog.ospattern.net
> _______________________________________________
> python-chinese
> Post: send python-chinese在lists.python.cn
> python-chinese在lists.python.cn>
> Subscribe: send subscribe to
> python-chinese-request在lists.python.cn
> python-chinese-request在lists.python.cn>
> Unsubscribe: send unsubscribe to
> python-chinese-request在lists.python.cn
> python-chinese-request在lists.python.cn>
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
>
>
>
> --
> 花开邑大,漫步心月湖。
> http://www.ewyu.com/
> ------------------------------------------------------------------------
>
> _______________________________________________
> python-chinese
> Post: send python-chinese在lists.python.cn
> Subscribe: send subscribe to python-chinese-request在lists.python.cn
> Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
2006年09月14日 星期四 09:58
¹ØÓÚ×ÖÌå±àÂëµÄÎÊÌ⣬ÕÛÌÚÁ˺ܳ¤Ê±¼ä£¬»¹ÊDz»ºÜÁ˽⡣ ÓÐûÀÏ´ó°ÑÏÂÃæÏ¹ÕÛÌڵĶ«¶«½âÎöһϡ£
>>> a='¸£ÖÝ'
>>> a
'\xb8\xa3\xd6\xdd' Õâ¸öÓ¦¸ÃÊÇ·µ»ØaµÄgb2312±àÂë
>>> b = unicode(a, 'gb2312')
>>> b
u'\u798f\u5dde' Õâ¸ö·µ»ØµÄÓÖÊÇɶ£¿unicode±àÂ룿¿É°Ñb´«Èëdjango¾Í»á³ö´í¡£µ«ÊÇ£¬print a b¶¼ÄÜÏÔʾ¡®¸£ÖÝ¡¯£¬Ææ¹Ö£¿
>>> c = b.encode('gb2312')
>>> c
'\xb8\xa3\xd6\xdd' cÓÖ±ä³Égb2312±àÂëÁË
>>> c.decode('gb2312')
u'\u798f\u5dde' ÓÖ·µ»Ø¸Õ²ÅÄǸöunicodeº¯ÊýµÄ·µ»ØÖµÁË
>>> c = b.encode('utf8')
>>> c
'\xe7\xa6\x8f\xe5\xb7\x9e' encode³Éutf8ºó£¬±àÂëÓÖ±äÁË¡£Ö±½Ó´òÓ¡c£¬ÒѾÊÇÂÒÂëÁË¡£¿É°Ñc´«ÈëdjangoµÄ»°£¬¾Í¿ÉÒÔÕý³£ÏÔʾ¡£
>>> print c
福州
>>> d = c.decode('utf8')
>>> d
u'\u798f\u5dde' djangoϵͳÀïÃæ×öÁËdecode('utf8')£¬ËùÒÔ£¬´«Èë²ÎÊýǰҪÏÈencodeһϣ¿
>>> print d
¸£ÖÝ
>>> g = u'¸£ÖÝ'
>>> g
u'\xb8\xa3\xd6\xdd' Õâ¸ö´øuµÄgb2312±àÂëÓÖÊÇϺÃ×Òâ˼£¿Ö±½Ó´òÓ¡Ò²ÊÇÂÒÂë¡£
>>> unicode(g, 'gb2312')
Traceback (most recent call last):
File "", line 1, in ?
TypeError: decoding Unicode is not supported ÏÖÔÚ²»ÄÜÓÃunicodeº¯ÊýÁË£¬ÄÇgËãÊÇʲô±àÂëµÄ£¿Ö±½Ó´òÓ¡Ò²ÊÇÂÒÂë
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ÖÂ
Àñ£¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡charles huang
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡hyy在fjii.com
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡2006-09-14
Zeuux © 2025
京ICP备05028076号