Menu

#66 Encode queries to unicode for MySQLdb 1.2.1

closed-accepted
None
5
2006-08-11
2006-05-27
Neil Muller
No

MySQLdb 1.2.1 assumes that queries will be unicode
objects rather than string objects. The attached patch
aims to do the right thing. The assumption about alwasy
encoding using the charset specified in the mysql URI
is somewhat questionable, and it may be better to try
and infer self.encoding from the locale instead.

Discussion

  • Oleg Broytman

    Oleg Broytman - 2006-06-07

    Logged In: YES
    user_id=4799

    Your patch starts with "if MySQLdb.version_info[0]>0...".
    You probably want "if MySQLdb.version_info[0]>1..."?

    Your patch adds "use_unicode"... which is already there. ;)

    BTW, in case of MySQLbd 1.2.1+ where self.need_unicode=True
    you probbaly wants to always set use_unicode to 1, no? What
    if the user sets use_unicode=False? Would MySQLdb revert to
    ascii queries and responces?

    Infering self.encoding from the environment is the
    application's task, I think. Let's the user decide what
    encoding (s)he wants.

     
  • Neil Muller

    Neil Muller - 2006-06-07

    Logged In: YES
    user_id=698097

    In my test cases, mysqldb required that the queries be
    unicode regardless of what use_unicode was set to, but I
    haven't looked into this closely. I'll review the logic of
    that carefully when I fix the other errors in the patch.

     
  • Neil Muller

    Neil Muller - 2006-06-25

    Updated patch to convert queries to unicode for MySQLdb 1.2.1 and later

     
  • Neil Muller

    Neil Muller - 2006-06-25

    Logged In: YES
    user_id=698097

    Updated patch uploaded.

    Looking at the mysqldb code more closely shows I
    misinterpreted charset in the previous patch. Charset is the
    encoding used by the MySQL database. Thus I've added a
    sqlobject_encoding field to the URI to allow specifying the
    encoding before the conversion to unicode.

    For cases where charset is not set, and use_unicode is
    false, it seems we still need to convert to unicode as
    MySQLdb still expects to conver the query from unicode.

     
  • Oleg Broytman

    Oleg Broytman - 2006-08-11

    Logged In: YES
    user_id=4799

    Applied and committed in the revision 1850 to the trunk,
    rev.1851 to the 0.7-branch.Thank you!

     
  • Oleg Broytman

    Oleg Broytman - 2006-08-11
    • assigned_to: nobody --> phd
    • status: open --> closed-accepted
     

Log in to post a comment.