summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/databases/mssql.py
diff options
context:
space:
mode:
authorRick Morrison <rickmorrison@gmail.com>2007-02-15 00:13:01 +0000
committerRick Morrison <rickmorrison@gmail.com>2007-02-15 00:13:01 +0000
commitd796ed2f8ec39264737a3ce0c66013c5c42d104d (patch)
tree209dd7e1bc4edbf6066d39f97a78d5bdc43e2a69 /lib/sqlalchemy/databases/mssql.py
parentd4326560c3d14487caf17e8af76441b1d47c38d8 (diff)
downloadsqlalchemy-d796ed2f8ec39264737a3ce0c66013c5c42d104d.tar.gz
MSSSQL is now passing unit tests (well, some) thanks to Paul Johnston
Diffstat (limited to 'lib/sqlalchemy/databases/mssql.py')
-rw-r--r--lib/sqlalchemy/databases/mssql.py27
1 files changed, 19 insertions, 8 deletions
diff --git a/lib/sqlalchemy/databases/mssql.py b/lib/sqlalchemy/databases/mssql.py
index a0ae9b967..295779173 100644
--- a/lib/sqlalchemy/databases/mssql.py
+++ b/lib/sqlalchemy/databases/mssql.py
@@ -123,7 +123,10 @@ class MSNumeric(sqltypes.Numeric):
return str(value)
def get_col_spec(self):
- return "NUMERIC(%(precision)s, %(length)s)" % {'precision': self.precision, 'length' : self.length}
+ if self.precision is None:
+ return "NUMERIC"
+ else:
+ return "NUMERIC(%(precision)s, %(length)s)" % {'precision': self.precision, 'length' : self.length}
class MSFloat(sqltypes.Float):
def get_col_spec(self):
@@ -194,7 +197,10 @@ class MSNVarchar(MSString):
"""NVARCHAR string, does unicode conversion if dialect.convert_encoding is true"""
impl = sqltypes.Unicode
def get_col_spec(self):
- return "NVARCHAR(%(length)s)" % {'length' : self.length}
+ if self.length:
+ return "NVARCHAR(%(length)s)" % {'length' : self.length}
+ else:
+ return "NTEXT"
if dbmodule and dbmodule.__name__ == 'adodbapi':
def convert_bind_param(self, value, dialect):
return value
@@ -297,8 +303,9 @@ class MSSQLExecutionContext(default.DefaultExecutionContext):
if hasattr(c,'sequence'):
self.HASIDENT = True
if engine.dialect.auto_identity_insert:
- if isinstance(parameters, list) and parameters[0].has_key(c.name):
- self.IINSERT = True
+ if isinstance(parameters, list):
+ if parameters[0].has_key(c.name):
+ self.IINSERT = True
elif parameters.has_key(c.name):
self.IINSERT = True
break
@@ -483,8 +490,8 @@ class MSSQLDialect(ansisql.ANSIDialect):
# Add constraints
RR = self.uppercase_table(ischema.ref_constraints) #information_schema.referential_constraints
TC = self.uppercase_table(ischema.constraints) #information_schema.table_constraints
- C = self.uppercase_table(ischema.column_constraints).alias('C') #information_schema.constraint_column_usage: the constrained column
- R = self.uppercase_table(ischema.column_constraints).alias('R') #information_schema.constraint_column_usage: the referenced column
+ C = self.uppercase_table(ischema.pg_key_constraints).alias('C') #information_schema.constraint_column_usage: the constrained column
+ R = self.uppercase_table(ischema.pg_key_constraints).alias('R') #information_schema.constraint_column_usage: the referenced column
# Primary key constraints
s = sql.select([C.c.column_name, TC.c.constraint_type], sql.and_(TC.c.constraint_name == C.c.constraint_name,
@@ -500,8 +507,10 @@ class MSSQLDialect(ansisql.ANSIDialect):
R.c.table_schema, R.c.table_name, R.c.column_name,
RR.c.constraint_name, RR.c.match_option, RR.c.update_rule, RR.c.delete_rule],
sql.and_(C.c.table_name == table.name,
+ C.c.table_schema == current_schema,
C.c.constraint_name == RR.c.constraint_name,
- R.c.constraint_name == RR.c.unique_constraint_name
+ R.c.constraint_name == RR.c.unique_constraint_name,
+ C.c.ordinal_position == R.c.ordinal_position
),
order_by = [RR.c.constraint_name])
rows = connection.execute(s).fetchall()
@@ -612,7 +621,8 @@ class MSSQLSchemaGenerator(ansisql.ANSISchemaGenerator):
colspec = self.preparer.format_column(column) + " " + column.type.engine_impl(self.engine).get_col_spec()
# install a IDENTITY Sequence if we have an implicit IDENTITY column
- if column.primary_key and column.autoincrement and isinstance(column.type, sqltypes.Integer) and not column.foreign_key:
+ if (not getattr(column.table, 'has_sequence', False)) and column.primary_key and \
+ column.autoincrement and isinstance(column.type, sqltypes.Integer) and not column.foreign_key:
if column.default is None or (isinstance(column.default, schema.Sequence) and column.default.optional):
column.sequence = schema.Sequence(column.name + '_seq')
@@ -620,6 +630,7 @@ class MSSQLSchemaGenerator(ansisql.ANSISchemaGenerator):
colspec += " NOT NULL"
if hasattr(column, 'sequence'):
+ column.table.has_sequence = True
colspec += " IDENTITY(%s,%s)" % (column.sequence.start or 1, column.sequence.increment or 1)
else:
default = self.get_column_default_string(column)