diff options
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r-- | lib/sqlalchemy/connectors/pyodbc.py | 12 | ||||
-rw-r--r-- | lib/sqlalchemy/dialects/mssql/pyodbc.py | 25 | ||||
-rw-r--r-- | lib/sqlalchemy/schema.py | 2 |
3 files changed, 35 insertions, 4 deletions
diff --git a/lib/sqlalchemy/connectors/pyodbc.py b/lib/sqlalchemy/connectors/pyodbc.py index 439b8f4fe..a684a2dcb 100644 --- a/lib/sqlalchemy/connectors/pyodbc.py +++ b/lib/sqlalchemy/connectors/pyodbc.py @@ -37,6 +37,10 @@ class PyODBCConnector(Connector): # if the libessqlsrv.so is detected easysoft = False + def __init__(self, supports_unicode_binds=None, **kw): + super(PyODBCConnector, self).__init__(**kw) + self._user_supports_unicode_binds = supports_unicode_binds + @classmethod def dbapi(cls): return __import__('pyodbc') @@ -119,8 +123,12 @@ class PyODBCConnector(Connector): # have not tried pyodbc + python3.1 yet. # Py2K self.supports_unicode_statements = not self.freetds and not self.easysoft - self.supports_unicode_binds = (not self.freetds or - self.freetds_driver_version >= '0.91') and not self.easysoft + if self._user_supports_unicode_binds is not None: + self.supports_unicode_binds = self._user_supports_unicode_binds + else: + self.supports_unicode_binds = (not self.freetds or + self.freetds_driver_version >= '0.91' + ) and not self.easysoft # end Py2K # run other initialization which asks for user name, etc. diff --git a/lib/sqlalchemy/dialects/mssql/pyodbc.py b/lib/sqlalchemy/dialects/mssql/pyodbc.py index 7b47004ea..434cfd43c 100644 --- a/lib/sqlalchemy/dialects/mssql/pyodbc.py +++ b/lib/sqlalchemy/dialects/mssql/pyodbc.py @@ -80,6 +80,31 @@ the python shell. For example:: >>> urllib.quote_plus('dsn=mydsn;Database=db') 'dsn%3Dmydsn%3BDatabase%3Ddb' +Unicode Binds +^^^^^^^^^^^^^ + +The current state of PyODBC on a unix backend with FreeTDS and/or +EasySoft is poor regarding unicode; different OS platforms and versions of UnixODBC +versus IODBC versus FreeTDS/EasySoft versus PyODBC itself dramatically +alter how strings are received. The PyODBC dialect attempts to use all the information +it knows to determine whether or not a Python unicode literal can be +passed directly to the PyODBC driver or not; while SQLAlchemy can encode +these to bytestrings first, some users have reported that PyODBC mis-handles +bytestrings for certain encodings and requires a Python unicode object, +while the author has observed widespread cases where a Python unicode +is completely misinterpreted by PyODBC, particularly when dealing with +the information schema tables used in table reflection, and the value +must first be encoded to a bytestring. + +It is for this reason that whether or not unicode literals for bound +parameters be sent to PyODBC can be controlled using the +``supports_unicode_binds`` parameter to ``create_engine()``. When +left at its default of ``None``, the PyODBC dialect will use its +best guess as to whether or not the driver deals with unicode literals +well. When ``False``, unicode literals will be encoded first, and when +``True`` unicode literals will be passed straight through. This is an interim +flag that hopefully should not be needed when the unicode situation stabilizes +for unix + PyODBC. New in 0.7.7. """ diff --git a/lib/sqlalchemy/schema.py b/lib/sqlalchemy/schema.py index d29514377..9746af228 100644 --- a/lib/sqlalchemy/schema.py +++ b/lib/sqlalchemy/schema.py @@ -2208,8 +2208,6 @@ class Index(ColumnCollectionMixin, SchemaItem): self.table = None # will call _set_parent() if table-bound column # objects are present - if not columns: - util.warn("No column names or expressions given for Index.") ColumnCollectionMixin.__init__(self, *columns) self.name = name self.unique = kw.pop('unique', False) |