]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Corrected MSSQL support for 0.6.
authorMichael Trier <mtrier@gmail.com>
Tue, 31 Mar 2009 19:29:27 +0000 (19:29 +0000)
committerMichael Trier <mtrier@gmail.com>
Tue, 31 Mar 2009 19:29:27 +0000 (19:29 +0000)
lib/sqlalchemy/dialects/mssql/base.py
lib/sqlalchemy/dialects/mssql/information_schema.py

index b03bc4f90a457d51ff5dae229cbaf66d6c98c06a..646520982f1d6f7fd754663d531a7baf41a23f51 100644 (file)
@@ -229,7 +229,7 @@ Known Issues
 """
 import datetime, decimal, inspect, operator, sys, re
 
-from sqlalchemy import sql, schema, exc, util
+from sqlalchemy import sql, schema as sa_schema, exc, util
 from sqlalchemy.sql import select, compiler, expression, operators as sql_operators, functions as sql_functions
 from sqlalchemy.engine import default, base, reflection
 from sqlalchemy import types as sqltypes
@@ -740,7 +740,7 @@ def _has_implicit_sequence(column):
         (
             column.default is None or 
             (
-                isinstance(column.default, schema.Sequence) and 
+                isinstance(column.default, sa_schema.Sequence) and 
                 column.default.optional)
             )
 
@@ -1145,7 +1145,7 @@ class MSDialect(default.DefaultDialect):
         return row is not None
 
     @reflection.cache
-    def get_schema_names(self, connection):
+    def get_schema_names(self, connection, **kw):
         s = sql.select([ischema.schemata.c.schema_name],
             order_by=[ischema.schemata.c.schema_name]
         )
@@ -1191,7 +1191,7 @@ class MSDialect(default.DefaultDialect):
             if 'primary key' not in row['index_description']:
                 indexes.append({
                     'name' : row['index_name'],
-                    'column_names' : row['index_keys'].split(','),
+                    'column_names' : [c.strip() for c in row['index_keys'].split(',')],
                     'unique': 'unique' in row['index_description']
                 })
         return indexes
@@ -1259,7 +1259,7 @@ class MSDialect(default.DefaultDialect):
             coltype = coltype(**kwargs)
             colargs = []
             if default is not None:
-                colargs.append(schema.DefaultClause(sql.text(default)))
+                colargs.append(sa_schema.DefaultClause(sql.text(default)))
             cdict = {
                 'name' : name,
                 'type' : coltype,
@@ -1344,12 +1344,14 @@ class MSDialect(default.DefaultDialect):
         return fkeys
 
     def reflecttable(self, connection, table, include_columns):
+        info_cache = {}
+
         # Get base columns
         if table.schema is not None:
             current_schema = table.schema
         else:
             current_schema = self.get_default_schema_name(connection)
-        columns = self.get_columns(connection, table.name, current_schema)
+        columns = self.get_columns(connection, table.name, current_schema, info_cache=info_cache)
 
         found_table = False
         for cdict in columns:
@@ -1361,7 +1363,7 @@ class MSDialect(default.DefaultDialect):
             found_table = True
             if include_columns and name not in include_columns:
                 continue
-            table.append_column(schema.Column(name, coltype, nullable=nullable, autoincrement=False, *colargs))
+            table.append_column(sa_schema.Column(name, coltype, nullable=nullable, autoincrement=False, *colargs))
         if not found_table:
             raise exc.NoSuchTableError(table.name)
 
@@ -1377,7 +1379,7 @@ class MSDialect(default.DefaultDialect):
                 ic = table.c[col_name]
                 ic.autoincrement = True
                 # setup a psuedo-sequence to represent the identity attribute - we interpret this at table.create() time as the identity attribute
-                ic.sequence = schema.Sequence(ic.name + '_identity', 1, 1)
+                ic.sequence = sa_schema.Sequence(ic.name + '_identity', 1, 1)
                 # MSSQL: only one identity per table allowed
                 cursor.close()
                 break
@@ -1395,7 +1397,7 @@ class MSDialect(default.DefaultDialect):
 
         # Primary key constraints
         pkeys = self.get_primary_keys(connection, table.name,
-                                      current_schema)
+                                      current_schema, info_cache=info_cache)
         for pkey in pkeys:
             if pkey in table.c:
                 table.primary_key.add(table.c[pkey])
@@ -1407,7 +1409,7 @@ class MSDialect(default.DefaultDialect):
             else:
                 return '.'.join([rschema, rtbl, rcol])
 
-        fkeys = self.get_foreign_keys(connection, table.name, current_schema)
+        fkeys = self.get_foreign_keys(connection, table.name, current_schema, info_cache=info_cache)
         for fkey_d in fkeys:
             fknm = fkey_d['name']
             scols = fkey_d['constrained_columns']
@@ -1417,13 +1419,12 @@ class MSDialect(default.DefaultDialect):
             # if the reflected schema is the default schema then don't set it because this will
             # play into the metadata key causing duplicates.
             if rschema == current_schema and not table.schema:
-                schema.Table(rtbl, table.metadata, autoload=True,
+                sa_schema.Table(rtbl, table.metadata, autoload=True,
                              autoload_with=connection)
             else:
-                schema.Table(rtbl, table.metadata, schema=rschema,
+                sa_schema.Table(rtbl, table.metadata, schema=rschema,
                              autoload=True, autoload_with=connection)
-            ##table.append_constraint(schema.ForeignKeyConstraint(scols, [_gen_fkref(table, s, t, c) for s, t, c in rcols], fknm, link_to_name=True))
-            table.append_constraint(schema.ForeignKeyConstraint(scols, [_gen_fkref(table, rschema, rtbl, c) for c in rcols], fknm, link_to_name=True))
+            table.append_constraint(sa_schema.ForeignKeyConstraint(scols, [_gen_fkref(table, rschema, rtbl, c) for c in rcols], fknm, link_to_name=True))
 
 # fixme.  I added this for the tests to run. -Randall
 MSSQLDialect = MSDialect
index 84269bf18171a8f0507ea21fdac9753531b58c62..0f6332b537791cfd763e6044cbb1b4b471ea1c88 100644 (file)
@@ -64,11 +64,11 @@ ref_constraints = Table("REFERENTIAL_CONSTRAINTS", ischema,
     schema="INFORMATION_SCHEMA")
 
 views = Table("VIEWS", ischema,
-    Column("TABLE_CATALOG", String),
-    Column("TABLE_SCHEMA", String),
-    Column("TABLE_NAME", String),
-    Column("VIEW_DEFINITION", String),
-    Column("CHECK_OPTION", String),
-    Column("IS_UPDATABLE", String),
+    Column("TABLE_CATALOG", String, key="table_catalog"),
+    Column("TABLE_SCHEMA", String, key="table_schema"),
+    Column("TABLE_NAME", String, key="table_name"),
+    Column("VIEW_DEFINITION", String, key="view_definition"),
+    Column("CHECK_OPTION", String, key="check_option"),
+    Column("IS_UPDATABLE", String, key="is_updatable"),
     schema="INFORMATION_SCHEMA")