From 47a799ecd5d03b78e5d67918302c0da2950d27b8 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 1 Apr 2012 19:42:54 -0400 Subject: [PATCH] - sql - [bug] Removed warning when Index is created with no columns; while this might not be what the user intended, it is a valid use case as an Index could be a placeholder for just an index of a certain name. - mssql - [feature] Added interim create_engine flag supports_unicode_binds to PyODBC dialect, to force whether or not the dialect passes Python unicode literals to PyODBC or not. --- CHANGES | 14 ++++++++++++++ lib/sqlalchemy/connectors/pyodbc.py | 12 ++++++++++-- lib/sqlalchemy/dialects/mssql/pyodbc.py | 25 +++++++++++++++++++++++++ lib/sqlalchemy/schema.py | 2 -- test/bootstrap/config.py | 1 + test/sql/test_constraints.py | 8 ++------ 6 files changed, 52 insertions(+), 10 deletions(-) diff --git a/CHANGES b/CHANGES index 727e7235f3..88ddad8f8f 100644 --- a/CHANGES +++ b/CHANGES @@ -28,6 +28,20 @@ CHANGES OrderingList from being pickleable [ticket:2454]. Courtesy Jeff Dairiki +- sql + - [bug] Removed warning when Index is created + with no columns; while this might not be what + the user intended, it is a valid use case + as an Index could be a placeholder for just an + index of a certain name. + +- mssql + - [feature] Added interim create_engine flag + supports_unicode_binds to PyODBC dialect, + to force whether or not the dialect + passes Python unicode literals to PyODBC + or not. + - postgresql - [feature] Added new for_update/with_lockmode() options for Postgresql: for_update="read"/ diff --git a/lib/sqlalchemy/connectors/pyodbc.py b/lib/sqlalchemy/connectors/pyodbc.py index 439b8f4fef..a684a2dcb6 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 7b47004ea8..434cfd43c8 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 d29514377d..9746af2287 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) diff --git a/test/bootstrap/config.py b/test/bootstrap/config.py index edf94fae5f..86dc78bcc4 100644 --- a/test/bootstrap/config.py +++ b/test/bootstrap/config.py @@ -53,6 +53,7 @@ def _list_dbs(*args): def _server_side_cursors(options, opt_str, value, parser): db_opts['server_side_cursors'] = True + def _zero_timeout(options, opt_str, value, parser): warnings.warn("--zero-timeout testing option is now on in all cases") diff --git a/test/sql/test_constraints.py b/test/sql/test_constraints.py index 2468786247..5ea5a7edaa 100644 --- a/test/sql/test_constraints.py +++ b/test/sql/test_constraints.py @@ -271,12 +271,8 @@ class ConstraintTest(fixtures.TestBase, AssertsExecutionResults, AssertsCompiled Index, "foo", 5 ) - def test_warn_no_columns(self): - assert_raises_message( - exc.SAWarning, - "No column names or expressions given for Index.", - Index, "foo" - ) + def test_no_warning_w_no_columns(self): + Index(name="foo") def test_raise_clauseelement_not_a_column(self): m = MetaData() -- 2.47.2