Encode queries to unicode for MySQLdb 1.2.1
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
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.
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.
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.
Updated patch to convert queries to unicode for MySQLdb 1.2.1 and later
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.
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!