]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
utf-8 encoding is switchable at the engine level, ticket [ticket:101]
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 10 Mar 2006 04:47:38 +0000 (04:47 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 10 Mar 2006 04:47:38 +0000 (04:47 +0000)
doc/build/content/dbengine.myt
lib/sqlalchemy/engine.py
lib/sqlalchemy/types.py

index 4ce3d1b00b0a6668ab0c5f412aab47037a6a75fd..0c54c3a7ca6aec25150d3b47b2cfdff82700431d 100644 (file)
         <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" &>
index d61320533963ec8d793670b52b6885eadaf06da8..269402f81db1678662e6ec6b9f71619053513dc3 100644 (file)
@@ -180,7 +180,7 @@ class SQLEngine(schema.SchemaEngine):
     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
@@ -197,6 +197,7 @@ class SQLEngine(schema.SchemaEngine):
         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()
index f8b2b490f3629d7394bbf1cbca4d5e2dc9785445..96e6f1edbd675034b9f84cc3230383ee1e51bf14 100644 (file)
@@ -77,12 +77,12 @@ class String(TypeEngine):
         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()
@@ -92,12 +92,12 @@ class String(TypeEngine):
 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