From: Mike Bayer Date: Fri, 10 Mar 2006 04:47:38 +0000 (+0000) Subject: utf-8 encoding is switchable at the engine level, ticket [ticket:101] X-Git-Tag: rel_0_1_4~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d333168e00cd8c56425afce3906e8f7439f1427a;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git utf-8 encoding is switchable at the engine level, ticket [ticket:101] --- diff --git a/doc/build/content/dbengine.myt b/doc/build/content/dbengine.myt index 4ce3d1b00b..0c54c3a7ca 100644 --- a/doc/build/content/dbengine.myt +++ b/doc/build/content/dbengine.myt @@ -103,6 +103,7 @@
  • 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 <% "(+)=" |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.
  • 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.
  • 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.
  • +
  • encoding='utf-8' : the encoding to use when doing unicode translations.
  • <&|doclib.myt:item, name="proxy", description="Using the Proxy Engine" &> diff --git a/lib/sqlalchemy/engine.py b/lib/sqlalchemy/engine.py index d613205339..269402f81d 100644 --- a/lib/sqlalchemy/engine.py +++ b/lib/sqlalchemy/engine.py @@ -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() diff --git a/lib/sqlalchemy/types.py b/lib/sqlalchemy/types.py index f8b2b490f3..96e6f1edbd 100644 --- a/lib/sqlalchemy/types.py +++ b/lib/sqlalchemy/types.py @@ -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