]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
mssql: - [bug] Fixed bug where reflection of primary key constraint
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 30 Sep 2012 22:23:21 +0000 (18:23 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 30 Sep 2012 22:23:21 +0000 (18:23 -0400)
    would double up columns if the same constraint/table
    existed in multiple schemas.
- force returns_rows to False for inserts where we know rows shouldnt be returned;
allows post_exec() to use the cursor without issue

CHANGES
lib/sqlalchemy/dialects/mssql/base.py
lib/sqlalchemy/engine/base.py
lib/sqlalchemy/engine/result.py
lib/sqlalchemy/testing/suite/test_ddl.py
lib/sqlalchemy/testing/suite/test_insert.py

diff --git a/CHANGES b/CHANGES
index 080e9d205c0553b7d3f167604e9681e94aebf866..d304488e2ec78abe2f2f2f31fa672488a414da10 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -967,6 +967,10 @@ are also present in 0.8.
     attribute, causing the construct to not compile
     correctly a second time.  [ticket:2545]
 
+  - [bug] Fixed bug where reflection of primary key constraint
+    would double up columns if the same constraint/table
+    existed in multiple schemas.
+
 0.7.8
 =====
 - orm
index 7552375875654e236d9ecb6ea1f0e71591382b8c..6dd25350fac07a813021ce2bb4d21a234455d99e 100644 (file)
@@ -1419,6 +1419,7 @@ class MSDialect(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,
+                    TC.c.table_schema == C.c.table_schema,
                      C.c.table_name == tablename,
                      C.c.table_schema == owner)
         )
index e8b22fdc645a090bc221d7855e6a171059139b96..05ca0f980dee67e2e8eee0f3823b81c9e09c3249 100644 (file)
@@ -882,8 +882,10 @@ class Connection(Connectable):
             if context._is_implicit_returning:
                 context._fetch_implicit_returning(result)
                 result.close(_autoclose_connection=False)
+                result._metadata = None
             elif not context._is_explicit_returning:
                 result.close(_autoclose_connection=False)
+                result._metadata = None
         elif result._metadata is None:
             # no results, get rowcount
             # (which requires open cursor on some drivers
index a9bb248b3ea4c6e06162e22893039bdd59c43e88..bf6410f155f58056ac4597ec75a2196d15465a75 100644 (file)
@@ -369,6 +369,7 @@ class ResultProxy(object):
     _process_row = RowProxy
     out_parameters = None
     _can_close_connection = False
+    _metadata = None
 
     def __init__(self, context):
         self.context = context
@@ -382,9 +383,7 @@ class ResultProxy(object):
 
     def _init_metadata(self):
         metadata = self._cursor_description()
-        if metadata is None:
-            self._metadata = None
-        else:
+        if metadata is not None:
             self._metadata = ResultMetaData(self, metadata)
 
     def keys(self):
index 2bd2518bf25398c1ba0e0a51b8d205a9b009cce5..466429aa5eaeb950de0671897abacecbb3ae2a81 100644 (file)
@@ -11,7 +11,7 @@ class TableDDLTest(fixtures.TestBase):
 
     def _simple_fixture(self):
         return Table('test_table', self.metadata,
-                Column('id', Integer, primary_key=True),
+                Column('id', Integer, primary_key=True, autoincrement=False),
                 Column('data', String(50))
             )
 
index 53a70e0c6a3987af3079ea69d551c6098a03619f..0a9896ffb438ba5b04b0c2d81556d0dbc4c3bcf5 100644 (file)
@@ -103,7 +103,7 @@ class InsertBehaviorTest(fixtures.TablesTest):
         )
         assert r.closed
         assert r.is_insert
-        assert r.returns_rows
+        assert not r.returns_rows
 
 
 __all__ = ('InsertSequencingTest', 'InsertBehaviorTest')