]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
mssql: now passes still more unit tests, [ticket:481]
authorRick Morrison <rickmorrison@gmail.com>
Mon, 19 Mar 2007 02:00:32 +0000 (02:00 +0000)
committerRick Morrison <rickmorrison@gmail.com>
Mon, 19 Mar 2007 02:00:32 +0000 (02:00 +0000)
CHANGES
lib/sqlalchemy/databases/mssql.py
test/ext/activemapper.py
test/orm/unitofwork.py

diff --git a/CHANGES b/CHANGES
index 2c73d0ab3af1f4120f57fd44f57586df262d7675..08febf731c9b189b0146eda2ab79d34d7ee7dc2f 100644 (file)
--- a/CHANGES
+++ b/CHANGES
       for large unsized string fields. Use the new "text_as_varchar" to 
       turn it on. [ticket:509]
 
+    - ORDER BY clauses without a LIMIT are now stripped in subqueries, as 
+      MS-SQL forbids this usage
+
     - cleanup of module importing code; specifiable DB-API module; more 
       explicit ordering of module preferences. [ticket:480]
 
@@ -1367,3 +1370,4 @@ different column name/column keys (changset 982)
 0.1.0
 initial release
 
+
index f16fcdc97dcf0447ed5ae0505731d5ef3062bcee..aa39e3e09803a97c621336848f7a9a8bb9b5fabe 100644 (file)
@@ -245,9 +245,9 @@ class MSSQLExecutionContext(default.DefaultExecutionContext):
             self.HASIDENT = bool(tbl.has_sequence)
             if engine.dialect.auto_identity_insert and self.HASIDENT:
                 if isinstance(parameters, list):
-                    self.IINSERT = parameters[0].has_key(tbl.has_sequence.name)
+                    self.IINSERT = parameters[0].has_key(tbl.has_sequence.key)
                 else:
-                    self.IINSERT = parameters.has_key(tbl.has_sequence.name)
+                    self.IINSERT = parameters.has_key(tbl.has_sequence.key)
             else:
                 self.IINSERT = False
 
@@ -540,7 +540,7 @@ class MSSQLDialect(ansisql.ANSIDialect):
                                 R.c.constraint_name == RR.c.unique_constraint_name,
                                 C.c.ordinal_position == R.c.ordinal_position
                                 ),
-                       order_by = [RR.c.constraint_name])
+                       order_by = [RR.c.constraint_name, R.c.ordinal_position])
         rows = connection.execute(s).fetchall()
 
         # group rows by constraint ID, to handle multi-column FKs
@@ -747,6 +747,16 @@ class MSSQLCompiler(ansisql.ANSICompiler):
         # "FOR UPDATE" is only allowed on "DECLARE CURSOR" which SQLAlchemy doesn't use
         return ''
 
+    def order_by_clause(self, select):
+        order_by = self.get_str(select.order_by_clause)
+
+        # MSSQL only allows ORDER BY in subqueries if there is a LIMIT
+        if order_by and (not select.is_subquery or select.limit):
+            return " ORDER BY " + order_by
+        else:
+            return ""
+
+
 class MSSQLSchemaGenerator(ansisql.ANSISchemaGenerator):
     def get_column_specification(self, column, **kwargs):
         colspec = self.preparer.format_column(column) + " " + column.type.engine_impl(self.engine).get_col_spec()
index 75bc34f502322cafb733f8821c26f168f5ad39c6..ebb832fdcd14a8f2b6002e5f233c4b99c54aa9af 100644 (file)
@@ -172,7 +172,9 @@ class testcase(testbase.PersistTest):
         try:
             objectstore.context.current = s1
             objectstore.flush()
-            assert False
+            # Only dialects with a sane rowcount can detect the ConcurrentModificationError
+            if testbase.db.dialect.supports_sane_rowcount():
+                assert False
         except exceptions.ConcurrentModificationError:
             pass
         
index 340515039a62dbe1f2b3671414bb52edcb11c819..598fba78040be6f94ac76afa3b78931427ea6978 100644 (file)
@@ -101,7 +101,6 @@ class VersioningTest(UnitOfWorkTest):
         version_table.delete().execute()
         UnitOfWorkTest.tearDown(self)
     
-    @testbase.unsupported('mssql')
     def testbasic(self):
         s = create_session()
         class Foo(object):pass
@@ -126,7 +125,10 @@ class VersioningTest(UnitOfWorkTest):
         except exceptions.ConcurrentModificationError, e:
             #print e
             success = True
-        assert success
+
+        # Only dialects with a sane rowcount can detect the ConcurrentModificationError
+        if testbase.db.dialect.supports_sane_rowcount():
+            assert success
         
         s.clear()
         f1 = s.query(Foo).get(f1.id)
@@ -142,7 +144,9 @@ class VersioningTest(UnitOfWorkTest):
         except exceptions.ConcurrentModificationError, e:
             #print e
             success = True
-        assert success
+        if testbase.db.dialect.supports_sane_rowcount():
+            assert success
+
     def testversioncheck(self):
         """test that query.with_lockmode performs a 'version check' on an already loaded instance"""
         s1 = create_session()
@@ -328,7 +332,6 @@ class MutableTypesTest(UnitOfWorkTest):
         
         
 class PKTest(UnitOfWorkTest):
-    @testbase.unsupported('mssql')
     def setUpAll(self):
         UnitOfWorkTest.setUpAll(self)
         global table
@@ -356,7 +359,7 @@ class PKTest(UnitOfWorkTest):
         table.create()
         table2.create()
         table3.create()
-    @testbase.unsupported('mssql')
+
     def tearDownAll(self):
         table.drop()
         table2.drop()
@@ -365,7 +368,7 @@ class PKTest(UnitOfWorkTest):
         
     # not support on sqlite since sqlite's auto-pk generation only works with
     # single column primary keys    
-    @testbase.unsupported('sqlite', 'mssql')
+    @testbase.unsupported('sqlite')
     def testprimarykey(self):
         class Entry(object):
             pass
@@ -380,7 +383,6 @@ class PKTest(UnitOfWorkTest):
         self.assert_(e is not e2 and e._instance_key == e2._instance_key)
         
     # this one works with sqlite since we are manually setting up pk values
-    @testbase.unsupported('mssql')
     def testmanualpk(self):
         class Entry(object):
             pass
@@ -391,7 +393,6 @@ class PKTest(UnitOfWorkTest):
         e.data = 'im the data'
         ctx.current.flush()
         
-    @testbase.unsupported('mssql')
     def testkeypks(self):
         import datetime
         class Entity(object):