From 951fe224fa5638e2c1c224f9ebfcaebb38e49922 Mon Sep 17 00:00:00 2001 From: Michael Trier Date: Wed, 23 Jul 2008 05:10:04 +0000 Subject: [PATCH] Corrected problem with detecting closed connections. Fixed issues in reflecttable for reflecting the mssql tables. Removed unicode reflection test from mssql. Need to investigate this further. --- lib/sqlalchemy/databases/mssql.py | 11 ++++++++--- test/engine/reflection.py | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/sqlalchemy/databases/mssql.py b/lib/sqlalchemy/databases/mssql.py index 5852b2c434..0341d18230 100644 --- a/lib/sqlalchemy/databases/mssql.py +++ b/lib/sqlalchemy/databases/mssql.py @@ -582,7 +582,7 @@ class MSSQLDialect(default.DefaultDialect): if a is not None: args.append(a) coltype = self.ischema_names.get(type, None) - if coltype == MSString and charlen == -1: + if coltype == MSText or (coltype == MSString and charlen == -1): coltype = MSText() else: if coltype is None: @@ -639,7 +639,7 @@ class MSSQLDialect(default.DefaultDialect): # Primary key constraints s = sql.select([C.c.column_name, TC.c.constraint_type], sql.and_(TC.c.constraint_name == C.c.constraint_name, C.c.table_name == table.name, - C.c.table_schema == table.schema)) + C.c.table_schema == (table.schema or current_schema))) c = connection.execute(s) for row in c: if 'PRIMARY' in row[TC.c.constraint_type.name]: @@ -804,7 +804,12 @@ class MSSQLDialect_pyodbc(MSSQLDialect): return [[";".join (connectors)], {}] def is_disconnect(self, e): - return isinstance(e, self.dbapi.Error) and '[08S01]' in str(e) + if isinstance(e, self.dbapi.ProgrammingError): + return "The cursor's connection has been closed." in str(e) or 'Attempt to use a closed connection.' in str(e) + elif isinstance(e, self.dbapi.Error): + return '[08S01]' in str(e) + else: + return False def create_execution_context(self, *args, **kwargs): return MSSQLExecutionContext_pyodbc(self, *args, **kwargs) diff --git a/test/engine/reflection.py b/test/engine/reflection.py index 3f8d4fff74..873c05aa53 100644 --- a/test/engine/reflection.py +++ b/test/engine/reflection.py @@ -618,7 +618,7 @@ class UnicodeReflectionTest(TestBase): bind = engines.utf8_engine(options={'convert_unicode':True}) metadata = MetaData(bind) - if testing.against('sybase', 'maxdb', 'oracle'): + if testing.against('sybase', 'maxdb', 'oracle', 'mssql'): names = set(['plain']) else: names = set([u'plain', u'Unit\u00e9ble', u'\u6e2c\u8a66']) -- 2.47.3