]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Changes to attempt support of FreeTDS 0.91 with
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 18 Sep 2011 19:33:12 +0000 (15:33 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 18 Sep 2011 19:33:12 +0000 (15:33 -0400)
    Pyodbc.  This includes that string binds are sent as
    Python unicode objects when FreeTDS 0.91 is detected,
    and a CAST(? AS NVARCHAR) is used when we detect
    for a table.   However, I'd continue
    to characterize Pyodbc + FreeTDS 0.91 behavior as
    pretty crappy, there are still many queries such
    as used in reflection which cause a core dump on
    Linux, and it is not really usable at all
    on OSX, MemoryErrors abound and just plain broken
    unicode support.   [ticket:2273]

CHANGES
lib/sqlalchemy/connectors/pyodbc.py
lib/sqlalchemy/dialects/mssql/base.py

diff --git a/CHANGES b/CHANGES
index 26b7c1428706444ab486418a38151913ab9e91b2..642fc50c3c6bdad905b4e7ef0ef5f85804f02c50 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -156,6 +156,18 @@ CHANGES
     with the full search_path.  [ticket:2249]
 
 - mssql
+  - Changes to attempt support of FreeTDS 0.91 with 
+    Pyodbc.  This includes that string binds are sent as 
+    Python unicode objects when FreeTDS 0.91 is detected,
+    and a CAST(? AS NVARCHAR) is used when we detect 
+    for a table.   However, I'd continue
+    to characterize Pyodbc + FreeTDS 0.91 behavior as 
+    pretty crappy, there are still many queries such 
+    as used in reflection which cause a core dump on 
+    Linux, and it is not really usable at all
+    on OSX, MemoryErrors abound and just plain broken 
+    unicode support.   [ticket:2273]
+
   - "0" is accepted as an argument for limit() which
     will produce "TOP 0". [ticket:2222]
 
index ea4810df7aad49ad3b6251fa6d5efefc72c5332d..562cf927352d7ca56e72c8958f8e77b24b34109b 100644 (file)
@@ -29,6 +29,10 @@ class PyODBCConnector(Connector):
     # if the freetds.so is detected
     freetds = False
 
+    # will be set to the string version of
+    # the FreeTDS driver if freetds is detected
+    freetds_driver_version = None
+
     # will be set to True after initialize()
     # if the libessqlsrv.so is detected
     easysoft = False
@@ -108,11 +112,15 @@ class PyODBCConnector(Connector):
         self.easysoft = bool(re.match(r".*libessqlsrv.*\.so", _sql_driver_name
                             ))
 
+        if self.freetds:
+            self.freetds_driver_version = dbapi_con.getinfo(pyodbc.SQL_DRIVER_VER)
+
         # the "Py2K only" part here is theoretical.
         # 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 and not self.easysoft
+        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.
index 015c346eb111f234ba9e47cedc28e58f68471c59..981ffc2384be9c4ffd8770d47c57e7ac3736ebaf 100644 (file)
@@ -171,7 +171,7 @@ import datetime, operator, re
 from sqlalchemy import sql, schema as sa_schema, exc, util
 from sqlalchemy.sql import select, compiler, expression, \
                             operators as sql_operators, \
-                            util as sql_util
+                            util as sql_util, cast
 from sqlalchemy.engine import default, base, reflection
 from sqlalchemy import types as sqltypes
 from sqlalchemy.types import INTEGER, BIGINT, SMALLINT, DECIMAL, NUMERIC, \
@@ -1135,11 +1135,10 @@ class MSDialect(default.DefaultDialect):
     def has_table(self, connection, tablename, schema=None):
         current_schema = schema or self.default_schema_name
         columns = ischema.columns
+        whereclause = cast(columns.c.table_name, NVARCHAR(_warn_on_bytestring=False))==tablename
         if current_schema:
-            whereclause = sql.and_(columns.c.table_name==tablename,
+            whereclause = sql.and_(whereclause,
                                    columns.c.table_schema==current_schema)
-        else:
-            whereclause = columns.c.table_name==tablename
         s = sql.select([columns], whereclause)
         c = connection.execute(s)
         return c.first() is not None