summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2006-03-10 04:47:38 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2006-03-10 04:47:38 +0000
commitd333168e00cd8c56425afce3906e8f7439f1427a (patch)
treeb29833ddb8cb0bddd04ac46951fe16f424054715
parent612205c3fd0e4f1f86ea7240ac7da6a681f66f44 (diff)
downloadsqlalchemy-d333168e00cd8c56425afce3906e8f7439f1427a.tar.gz
utf-8 encoding is switchable at the engine level, ticket [ticket:101]
-rw-r--r--doc/build/content/dbengine.myt1
-rw-r--r--lib/sqlalchemy/engine.py3
-rw-r--r--lib/sqlalchemy/types.py8
3 files changed, 7 insertions, 5 deletions
diff --git a/doc/build/content/dbengine.myt b/doc/build/content/dbengine.myt
index 4ce3d1b00..0c54c3a7c 100644
--- a/doc/build/content/dbengine.myt
+++ b/doc/build/content/dbengine.myt
@@ -103,6 +103,7 @@
<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" &>
diff --git a/lib/sqlalchemy/engine.py b/lib/sqlalchemy/engine.py
index d61320533..269402f81 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 f8b2b490f..96e6f1edb 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