From: Derek Harland Date: Mon, 14 Jan 2013 04:00:37 +0000 (+1300) Subject: Add mssql_clustered option for mssql dialect X-Git-Tag: rel_0_8_0~29^2~1^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7198abb13e464b32639d03dc5987457ba64281c4;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Add mssql_clustered option for mssql dialect --- diff --git a/lib/sqlalchemy/dialects/mssql/base.py b/lib/sqlalchemy/dialects/mssql/base.py index d7c29654a3..74d1a13203 100644 --- a/lib/sqlalchemy/dialects/mssql/base.py +++ b/lib/sqlalchemy/dialects/mssql/base.py @@ -932,6 +932,26 @@ class MSDDLCompiler(compiler.DDLCompiler): return colspec + def visit_create_index(self, create, include_schema=False): + index = create.element + preparer = self.preparer + text = "CREATE " + if index.unique: + text += "UNIQUE " + + # handle clustering option + if index.kwargs.get("mssql_clustered"): + text += "CLUSTERED " + + text += "INDEX %s ON %s (%s)" \ + % ( + self._prepared_index_name(index, + include_schema=include_schema), + preparer.format_table(index.table), + ', '.join(preparer.quote(c.name, c.quote) + for c in index.columns)) + return text + def visit_drop_index(self, drop): return "\nDROP INDEX %s.%s" % ( self.preparer.quote_identifier(drop.element.table.name), diff --git a/test/dialect/test_mssql.py b/test/dialect/test_mssql.py index 8c1c0873a1..346022c315 100644 --- a/test/dialect/test_mssql.py +++ b/test/dialect/test_mssql.py @@ -506,6 +506,15 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): "CREATE TABLE test (id INTEGER NOT NULL IDENTITY(1,1))" ) + def test_index_clustering(self): + metadata = MetaData() + tbl = Table('test', metadata, + Column('id', Integer)) + idx = Index("foo", tbl.c.id, mssql_clustered=True) + self.assert_compile(schema.CreateIndex(idx), + "CREATE CLUSTERED INDEX foo ON test (id)" + ) + class SchemaAliasingTest(fixtures.TestBase, AssertsCompiledSQL): """SQL server cannot reference schema-qualified tables in a SELECT statement, they must be aliased.