I'd like to ask MySQL users to look at the patch. I am afraid it chnages
too much at once.

1. "charset" and "sqlobject_encoding" are not the same thing.
2. I've heard many times it is not neccessary to run SET NAMES query -
MySQLdb runs it itself if there is "charset" parameter.
3. "if self.need_unicode and not isinstance(query, unicode):" - when does
the query become unicode?

On Wed, Feb 07, 2007 at 06:54:11AM -0800, SourceForge.net wrote:
> Patches item #1653898, was opened at 2007-02-07 09:57
> Message generated for change (Comment added) made by mfi
> You can respond by visiting: 
> https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1653898&group_id=74338
> 
> Please note that this message will contain a full copy of the comment thread,
> including the initial issue submission, for this request,
> not just the latest update.
> Category: None
> Group: None
> Status: Open
> Resolution: None
> Priority: 5
> Private: No
> Submitted By: Maxim F. Ischenko (mfi)
> Assigned to: Oleg Broytmann (phd)
> Summary: proper init mysql conn encoding 
> 
> Initial Comment:
> Current implementation of the mysqlconnection.py accepts 'sqlobject_encoding' 
> and 'charset' parameters but doesn't quite properly use them.
> 
> In particular, MySQLdb does query.encode(charset) call in execute() where 
> charset is taken from conn.get_character_name(). The problem is - SQLObject 
> never initializes it properly. 
> 
> This one-line patch fixes it by adding a call to conn.set_character_set() in 
> makeConnection() helper.
> 
> Index: sqlobject/mysql/mysqlconnection.py
> ===================================================================
> --- sqlobject/mysql/mysqlconnection.py  (revision 2269)
> +++ sqlobject/mysql/mysqlconnection.py  (working copy)
> @@ -62,6 +62,8 @@
>          if hasattr(conn, 'autocommit'):
>              conn.autocommit(bool(self.autoCommit))
>  
> +        conn.set_character_set(self.encoding)
> +
>          return conn
>  
>      def _setAutoCommit(self, conn, auto):
> 
> 
> ----------------------------------------------------------------------
> 
> >Comment By: Maxim F. Ischenko (mfi)
> Date: 2007-02-07 16:54
> 
> Message:
> Logged In: YES 
> user_id=113894
> Originator: YES
> 
> Note that I also had to tweak UnicodeStringLikeConvertor so that unicode
> parameters are encoded into utf8. Without this tweak I got errors like this
> one when unicode parameters are passed into queries built with sqlbuilder:
> 
>   File "/home/max/oss-projects/SQLObject-0.7/sqlobject/sqlbuilder.py",
> line 237, in __sqlrepr__
>     return "(%s %s %s)" % (s1, self.op, s2)
> UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 19:
> ordinal not in range(128)
> 
> The converter trick is controversial but I haven't found a better
> solution. ;(
> 
> 
> ----------------------------------------------------------------------
> 
> Comment By: Maxim F. Ischenko (mfi)
> Date: 2007-02-07 16:46
> 
> Message:
> Logged In: YES 
> user_id=113894
> Originator: YES
> 
> It was tested against MySQL 4.1 (5.x should work while 4.0 shouldn't) and
> MySQLdb driver versions 1.2.0 and 1.2.1. I only tested  it with utf8
> encoding, the other ones like latin1 should work though I don't know why
> would you want to use them.
> 
> ----------------------------------------------------------------------
> 
> Comment By: Maxim F. Ischenko (mfi)
> Date: 2007-02-07 16:44
> 
> Message:
> Logged In: YES 
> user_id=113894
> Originator: YES
> 
> Please ignore that one-line fix; it won't work with MySQLdb 1.2.0 and
> there are other issues as I have discovered during testing. I attached new
> patch which is quite more involved. ;)
> 
> ----------------------------------------------------------------------
> 
> Comment By: Maxim F. Ischenko (mfi)
> Date: 2007-02-07 16:42
> 
> Message:
> Logged In: YES 
> user_id=113894
> Originator: YES
> 
> File Added: mysql_charset.patch
> 
> ----------------------------------------------------------------------
> 
> Comment By: Oleg Broytmann (phd)
> Date: 2007-02-07 10:34
> 
> Message:
> Logged In: YES 
> user_id=4799
> Originator: NO
> 
> Thank you. Does all MySQLdb versions have the call or have I test "if
> hasattr(conn, 'set_character_set')"?
> 
> ----------------------------------------------------------------------
> 
> You can respond by visiting: 
> https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1653898&group_id=74338
> 
> -------------------------------------------------------------------------
> Using Tomcat but need to do more? Need to support web services, security?
> Get stuff done quickly with pre-integrated technology to make your job easier.
> Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
> _______________________________________________
> sqlobject-cvs mailing list
> [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/sqlobject-cvs

Oleg.
-- 
     Oleg Broytmann            http://phd.pp.ru/            [EMAIL PROTECTED]
           Programmers don't die, they just GOSUB without RETURN.

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss

Reply via email to