summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/dialects
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2013-01-12 11:43:36 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2013-01-12 11:43:36 -0500
commit17c300eb07b775424d99eb47802fd9385050827e (patch)
treeebab7aa315e0eddfc24be1b1d625addbb32bf74e /lib/sqlalchemy/dialects
parent274fec2460540574265ed851a9d60e43ba4d4f57 (diff)
parent72b1f475afe8892edf8fd6d966244ff7c5d31228 (diff)
downloadsqlalchemy-17c300eb07b775424d99eb47802fd9385050827e.tar.gz
Merged in dharland/sqlalchemy (pull request #32: Allow the MSSQL dialect to support identity columns that are not part of the primary key)
Diffstat (limited to 'lib/sqlalchemy/dialects')
-rw-r--r--lib/sqlalchemy/dialects/mssql/base.py23
1 files changed, 11 insertions, 12 deletions
diff --git a/lib/sqlalchemy/dialects/mssql/base.py b/lib/sqlalchemy/dialects/mssql/base.py
index e7d47ae6a..9cfe3b997 100644
--- a/lib/sqlalchemy/dialects/mssql/base.py
+++ b/lib/sqlalchemy/dialects/mssql/base.py
@@ -1018,7 +1018,8 @@ class MSDDLCompiler(compiler.DDLCompiler):
+ self.dialect.type_compiler.process(column.type))
if column.nullable is not None:
- if not column.nullable or column.primary_key:
+ if not column.nullable or column.primary_key or \
+ isinstance(column.default, sa_schema.Sequence):
colspec += " NOT NULL"
else:
colspec += " NULL"
@@ -1028,18 +1029,16 @@ class MSDDLCompiler(compiler.DDLCompiler):
"mssql requires Table-bound columns "
"in order to generate DDL")
- seq_col = column.table._autoincrement_column
-
- # install a IDENTITY Sequence if we have an implicit IDENTITY column
- if seq_col is column:
- sequence = isinstance(column.default, sa_schema.Sequence) and \
- column.default
- if sequence:
- start, increment = sequence.start or 1, \
- sequence.increment or 1
+ # install an IDENTITY Sequence if we either a sequence or an implicit IDENTITY column
+ if isinstance(column.default, sa_schema.Sequence):
+ if column.default.start == 0:
+ start = 0
else:
- start, increment = 1, 1
- colspec += " IDENTITY(%s,%s)" % (start, increment)
+ start = column.default.start or 1
+
+ colspec += " IDENTITY(%s,%s)" % (start, column.default.increment or 1)
+ elif column is column.table._autoincrement_column:
+ colspec += " IDENTITY(1,1)"
else:
default = self.get_column_default_string(column)
if default is not None: