summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2013-01-20 12:23:39 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2013-01-20 12:23:39 -0500
commitbc75bbd62d87ff12ceb5db711652903b0973d9e6 (patch)
tree9c970e34fd0fdf85ddadc63624fa4200c5d66f2d /lib/sqlalchemy
parentcfb037cfb1e8fe9b2976462f1c58da3c2573b4c7 (diff)
parentf5a5a6bf43faf53569f21cf05d4a28a4ba1f5229 (diff)
downloadsqlalchemy-bc75bbd62d87ff12ceb5db711652903b0973d9e6.tar.gz
Merged in dharland/sqlalchemy (pull request #35)
Add extra mssql dialect options to Index
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r--lib/sqlalchemy/dialects/mssql/base.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/lib/sqlalchemy/dialects/mssql/base.py b/lib/sqlalchemy/dialects/mssql/base.py
index 58ed65bc9..084d00bef 100644
--- a/lib/sqlalchemy/dialects/mssql/base.py
+++ b/lib/sqlalchemy/dialects/mssql/base.py
@@ -932,6 +932,43 @@ 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 "
+
+ # extend the custom ordering to the right length
+ ordering = index.kwargs.get("mssql_ordering", [])
+ if len(ordering) > len(index.columns):
+ raise ValueError("Column ordering length is incompatible with index columns")
+ elif len(ordering) < len(index.columns):
+ ordering.extend([""]*(len(index.columns) - len(ordering)))
+
+ 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) + (" " + o if o else "")
+ for c, o in zip(index.columns, ordering)]))
+
+ # handle other included columns
+ if index.kwargs.get("mssql_include"):
+ inclusions = [index.table.c[col] if isinstance(col, basestring) else col
+ for col in index.kwargs["mssql_include"]]
+
+ text += " INCLUDE (%s)" \
+ % ', '.join([preparer.quote(c.name, c.quote)
+ for c in inclusions])
+
+ return text
+
def visit_drop_index(self, drop):
return "\nDROP INDEX %s.%s" % (
self.preparer.quote_identifier(drop.element.table.name),