From e7da05f64eee0177b43162301710012211377a8e Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Wed, 28 Mar 2007 15:53:18 +0000 Subject: [PATCH] added "supports_unicode_statements()" step to dialect/execute_raw so that DB's like oracle can opt out of unicode statement strings --- lib/sqlalchemy/databases/oracle.py | 4 ++++ lib/sqlalchemy/engine/base.py | 7 +++++++ lib/sqlalchemy/engine/default.py | 4 ++++ 3 files changed, 15 insertions(+) diff --git a/lib/sqlalchemy/databases/oracle.py b/lib/sqlalchemy/databases/oracle.py index be53109a5c..4633a0a8c9 100644 --- a/lib/sqlalchemy/databases/oracle.py +++ b/lib/sqlalchemy/databases/oracle.py @@ -193,6 +193,10 @@ class OracleDialect(ansisql.ANSIDialect): def type_descriptor(self, typeobj): return sqltypes.adapt_type(typeobj, colspecs) + def supports_unicode_statements(self): + """indicate whether the DBAPI can receive SQL statements as Python unicode strings""" + return False + def max_identifier_length(self): return 30 diff --git a/lib/sqlalchemy/engine/base.py b/lib/sqlalchemy/engine/base.py index c2ae272f51..cf0d350358 100644 --- a/lib/sqlalchemy/engine/base.py +++ b/lib/sqlalchemy/engine/base.py @@ -111,6 +111,10 @@ class Dialect(sql.AbstractDialect): Return None if no limit.""" return None + def supports_unicode_statements(self): + """indicate whether the DBAPI can receive SQL statements as Python unicode strings""" + raise NotImplementedError() + def supports_sane_rowcount(self): """Indicate whether the dialect properly implements statements rowcount. @@ -544,6 +548,9 @@ class Connection(Connectable): def _execute_raw(self, statement, parameters=None, cursor=None, context=None, **kwargs): if cursor is None: cursor = self.__engine.dialect.create_cursor(self.connection) + if not self.__engine.dialect.supports_unicode_statements(): + # encode to ascii, with full error handling + statement = statement.encode('ascii') self.__engine.logger.info(statement) self.__engine.logger.info(repr(parameters)) if parameters is not None and isinstance(parameters, list) and len(parameters) > 0 and (isinstance(parameters[0], list) or isinstance(parameters[0], dict)): diff --git a/lib/sqlalchemy/engine/default.py b/lib/sqlalchemy/engine/default.py index e9ea6c1498..86563cd7cb 100644 --- a/lib/sqlalchemy/engine/default.py +++ b/lib/sqlalchemy/engine/default.py @@ -48,6 +48,10 @@ class DefaultDialect(base.Dialect): typeobj = typeobj() return typeobj + def supports_unicode_statements(self): + """indicate whether the DBAPI can receive SQL statements as Python unicode strings""" + return True + def max_identifier_length(self): # TODO: probably raise this and fill out # db modules better -- 2.47.2