From: Rick Morrison Date: Mon, 19 Mar 2007 02:00:32 +0000 (+0000) Subject: mssql: now passes still more unit tests, [ticket:481] X-Git-Tag: rel_0_3_6~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0a0925661959ffef5ef6494f8f01aaedcc192834;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git mssql: now passes still more unit tests, [ticket:481] --- diff --git a/CHANGES b/CHANGES index 2c73d0ab3a..08febf731c 100644 --- a/CHANGES +++ b/CHANGES @@ -167,6 +167,9 @@ 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 + diff --git a/lib/sqlalchemy/databases/mssql.py b/lib/sqlalchemy/databases/mssql.py index f16fcdc97d..aa39e3e098 100644 --- a/lib/sqlalchemy/databases/mssql.py +++ b/lib/sqlalchemy/databases/mssql.py @@ -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() diff --git a/test/ext/activemapper.py b/test/ext/activemapper.py index 75bc34f502..ebb832fdcd 100644 --- a/test/ext/activemapper.py +++ b/test/ext/activemapper.py @@ -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 diff --git a/test/orm/unitofwork.py b/test/orm/unitofwork.py index 340515039a..598fba7804 100644 --- a/test/orm/unitofwork.py +++ b/test/orm/unitofwork.py @@ -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):