From: Mike Bayer Date: Wed, 28 Mar 2007 15:53:18 +0000 (+0000) Subject: added "supports_unicode_statements()" step to dialect/execute_raw so that DB's like... X-Git-Tag: rel_0_3_7~98 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e7da05f64eee0177b43162301710012211377a8e;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git added "supports_unicode_statements()" step to dialect/execute_raw so that DB's like oracle can opt out of unicode statement strings --- 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