On Tue, Nov 27, 2007 at 08:17:55PM +0100, Markus Gritsch wrote:
> use_unicode specifies only if MySQLdb should *return* string values as
> unicode or as strings.  Queries can be issued using unicode or string
> regardless of this parameter.

   This means SQLObject doesn't need to encode queries at all. Not only we
can remove that try/except, but remove the call to unicode() completely.
   Well, what do you think about the attached patch? It removes
need_unicode and the call unicode(). It also ignores sqlobject_encoding
because self.encoding is no longer needed. Probably SQLObject should issue
a warning on sqlobject_encoding instead of silently ignore it.
   Please test the patch.

Oleg.
-- 
     Oleg Broytmann            http://phd.pp.ru/            [EMAIL PROTECTED]
           Programmers don't die, they just GOSUB without RETURN.
Index: mysqlconnection.py
===================================================================
--- mysqlconnection.py  (revision 3162)
+++ mysqlconnection.py  (working copy)
@@ -19,10 +19,6 @@
         self.user = user
         self.password = passwd
         self.kw = {}
-        if MySQLdb.version_info[:3] >= (1, 2, 1):
-            self.need_unicode = True
-        else:
-            self.need_unicode = False
         for key in ("unix_socket", "init_command",
                 "read_default_file", "read_default_group"):
             if key in kw:
@@ -35,10 +31,6 @@
             self.dbEncoding = self.kw["charset"] = col.popKey(kw, "charset")
         else:
             self.dbEncoding = None
-        if "sqlobject_encoding" in kw:
-            self.encoding = col.popKey(kw, "sqlobject_encoding")
-        else:
-            self.encoding = 'ascii'
         DBAPI.__init__(self, **kw)
 
     def connectionFromURI(cls, uri):
@@ -70,12 +62,12 @@
         if hasattr(conn, 'autocommit'):
             conn.autocommit(bool(self.autoCommit))
 
-        if self.dbEncoding:
+        if dbEncoding:
             if hasattr(conn, 'set_character_set'): # MySQLdb 1.2.1 and later
-                conn.set_character_set(self.dbEncoding)
+                conn.set_character_set(dbEncoding)
             else: # pre MySQLdb 1.2.1
                 # works along with monkeypatching code above
-                conn.query("SET NAMES %s" % self.dbEncoding)
+                conn.query("SET NAMES %s" % dbEncoding)
 
         return conn
 
@@ -86,13 +78,6 @@
     def _executeRetry(self, conn, cursor, query):
         while 1:
             try:
-                # For MySQLdb 1.2.1 and later, we go
-                # encoding->unicode->charset (in the mysql db)
-                if self.need_unicode and not isinstance(query, unicode):
-                    try:
-                        query = unicode(query, self.encoding)
-                    except UnicodeError:
-                        pass                        
                 return cursor.execute(query)
             except MySQLdb.OperationalError, e:
                 if e.args[0] == 2013: # SERVER_LOST error
@@ -174,10 +159,10 @@
                 colClass = col.UnicodeCol
             kw['name'] = soClass.sqlmeta.style.dbColumnToPythonAttr(field)
             kw['dbName'] = field
-            
+
             # Since MySQL 5.0, 'NO' is returned in the NULL column (SQLObject 
expected '')
             kw['notNone'] = (nullAllowed.upper() != 'YES' and True or False)
-            
+
             if default and t.startswith('int'):
                 kw['default'] = int(default)
             elif default and t.startswith('float'):
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss

Reply via email to