summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/databases/mssql.py
diff options
context:
space:
mode:
authorMichael Trier <mtrier@gmail.com>2008-12-12 04:49:24 +0000
committerMichael Trier <mtrier@gmail.com>2008-12-12 04:49:24 +0000
commitf9b8641269b17a5f29ed58df46286f881d82035f (patch)
tree2c1e8f9b5a9e812fdb3fdfc1e55387f5ddfa2aca /lib/sqlalchemy/databases/mssql.py
parent1d90146210b0919294a99468a916d4084fc14c7d (diff)
downloadsqlalchemy-f9b8641269b17a5f29ed58df46286f881d82035f.tar.gz
Support for three levels of column nullability: NULL, NOT NULL, and the database's configured default.
The default Column configuration (nullable=True) will now generate NULL in the DDL. Previously no specification was emitted and the database default would take effect (usually NULL, but not always). To explicitly request the database default, configure columns with nullable=None and no specification will be emitted in DDL. Fixes #1243.
Diffstat (limited to 'lib/sqlalchemy/databases/mssql.py')
-rw-r--r--lib/sqlalchemy/databases/mssql.py22
1 files changed, 19 insertions, 3 deletions
diff --git a/lib/sqlalchemy/databases/mssql.py b/lib/sqlalchemy/databases/mssql.py
index c4a773426..5fb4361b9 100644
--- a/lib/sqlalchemy/databases/mssql.py
+++ b/lib/sqlalchemy/databases/mssql.py
@@ -14,7 +14,7 @@
CREATE TABLE test (
id INTEGER NOT NULL IDENTITY(100,10) PRIMARY KEY,
- name VARCHAR(20)
+ name VARCHAR(20) NULL,
)
Note that the start & increment values for sequences are optional
@@ -29,6 +29,19 @@
* Experimental implemention of LIMIT / OFFSET with row_number()
+* Support for three levels of column nullability provided. The default
+ nullability allows nulls::
+
+ name VARCHAR(20) NULL
+
+ If ``nullable=None`` is specified then no specification is made. In other
+ words the database's configured default is used. This will render::
+
+ name VARCHAR(20)
+
+ If ``nullable`` is True or False then the column will be ``NULL` or
+ ``NOT NULL`` respectively.
+
Known issues / TODO:
* No support for more than one ``IDENTITY`` column per table
@@ -1069,8 +1082,11 @@ class MSSQLSchemaGenerator(compiler.SchemaGenerator):
if column.default is None or (isinstance(column.default, schema.Sequence) and column.default.optional):
column.sequence = schema.Sequence(column.name + '_seq')
- if not column.nullable:
- colspec += " NOT NULL"
+ if column.nullable is not None:
+ if not column.nullable:
+ colspec += " NOT NULL"
+ else:
+ colspec += " NULL"
if hasattr(column, 'sequence'):
column.table.has_sequence = column