Mike Bayer avatar Mike Bayer committed b5bde4d

utf-8 encoding is switchable at the engine level, ticket [ticket:101]

Comments (0)

Files changed (3)

doc/build/content/dbengine.myt

         <li>use_ansi=True : used only by Oracle;  when False, the Oracle driver attempts to support a particular "quirk" of some Oracle databases, that the LEFT OUTER JOIN SQL syntax is not supported, and the "Oracle join" syntax of using <% "<column1>(+)=<column2>" |h%> must be used in order to achieve a LEFT OUTER JOIN.  Its advised that the Oracle database be configured to have full ANSI support instead of using this feature.</li>
         <li>use_oids=False : used only by Postgres, will enable the column name "oid" as the object ID column.  Postgres as of 8.1 has object IDs disabled by default.</li>
         <li>convert_unicode=False : if set to True, all String/character based types will convert Unicode values to raw byte values going into the database, and all raw byte values to Python Unicode coming out in result sets.  This is an engine-wide method to provide unicode across the board.  For unicode conversion on a column-by-column level, use the Unicode column type instead.</li>
+	<li>encoding='utf-8' : the encoding to use when doing unicode translations.</li>
     </ul>
     </&>
     <&|doclib.myt:item, name="proxy", description="Using the Proxy Engine" &>

lib/sqlalchemy/engine.py

     SQLEngines are constructed via the create_engine() function inside this package.
     """
     
-    def __init__(self, pool=None, echo=False, logger=None, default_ordering=False, echo_pool=False, echo_uow=False, convert_unicode=False, **params):
+    def __init__(self, pool=None, echo=False, logger=None, default_ordering=False, echo_pool=False, echo_uow=False, convert_unicode=False, encoding='utf-8', **params):
         """constructs a new SQLEngine.   SQLEngines should be constructed via the create_engine()
         function which will construct the appropriate subclass of SQLEngine."""
         # get a handle on the connection pool via the connect arguments
         self.echo = echo
         self.echo_uow = echo_uow
         self.convert_unicode = convert_unicode
+        self.encoding = encoding
         self.context = util.ThreadLocal(raiseerror=False)
         self._ischema = None
         self._figure_paramstyle()

lib/sqlalchemy/types.py

         if not engine.convert_unicode or value is None or not isinstance(value, unicode):
             return value
         else:
-            return value.encode('utf-8')
+            return value.encode(engine.encoding)
     def convert_result_value(self, value, engine):
         if not engine.convert_unicode or value is None or isinstance(value, unicode):
             return value
         else:
-            return value.decode('utf-8')
+            return value.decode(engine.encoding)
     def adapt_args(self):
         if self.length is None:
             return TEXT()
 class Unicode(String):
     def convert_bind_param(self, value, engine):
          if isinstance(value, unicode):
-              return value.encode('utf-8')
+              return value.encode(engine.encoding)
          else:
               return value
     def convert_result_value(self, value, engine):
          if not isinstance(value, unicode):
-             return value.decode('utf-8')
+             return value.decode(engine.encoding)
          else:
              return value
               
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.