Commits

Anonymous committed 83e5118

* Formatting changes in creation/introspection

Comments (0)

Files changed (2)

source/sqlserver_ado/creation.py

 # This dictionary maps Field objects to their associated Server Server column
 # types, as strings. Column-type strings can contain format strings; they'll
-# be interpolated against the values of Field.__dict__ before being output.
+# be interpolated against the values of Field.__dict__.
 from django.db.backends.creation import BaseDatabaseCreation
 
 class DatabaseCreation(BaseDatabaseCreation):

source/sqlserver_ado/introspection.py

         return [row[0] for row in cursor.fetchall()]
     
     def _is_auto_field(self, cursor, table_name, column_name):
-        """Checks whether column is an identity column, using COLUMNPROPERTY."""
-        # COLUMNPROPERTY: http://msdn2.microsoft.com/en-us/library/ms174968.aspx
+        """Checks whether column is an identity column, using COLUMNPROPERTY.
+        
+        See: http://msdn2.microsoft.com/en-us/library/ms174968.aspx
+        """
         sql = "SELECT COLUMNPROPERTY(OBJECT_ID(N'%s'), N'%s', 'IsIdentity')" % \
             (table_name, column_name)
-    
+
         cursor.execute(sql)      
-        return cursor.fetchall()[0][0]
+        return cursor.fetchone()[0]
     
     def get_table_description(self, cursor, table_name, identity_check=True):
         """Returns a description of the table, with DB-API cursor.description interface.
         source_field_dict = self._name_to_index(cursor, table_name)
         
         sql = """
-SELECT
-COLUMN_NAME = FK_COLS.COLUMN_NAME,
-REFERENCED_TABLE_NAME = PK.TABLE_NAME,
-REFERENCED_COLUMN_NAME = PK_COLS.COLUMN_NAME
-FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS REF_CONST
-JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS FK
-	ON REF_CONST.CONSTRAINT_CATALOG = FK.CONSTRAINT_CATALOG
-	AND REF_CONST.CONSTRAINT_SCHEMA = FK.CONSTRAINT_SCHEMA
-	AND REF_CONST.CONSTRAINT_NAME = FK.CONSTRAINT_NAME
-	AND FK.CONSTRAINT_TYPE = 'FOREIGN KEY'
+select
+    column_name = fk_cols.column_name,
+    referenced_table_name = pk.table_name,
+    referenced_column_name = pk_cols.column_name
+from information_schema.referential_constraints ref_const
+join information_schema.table_constraints fk
+	on ref_const.constraint_catalog = fk.constraint_catalog
+	and ref_const.constraint_schema = fk.constraint_schema
+	and ref_const.constraint_name = fk.constraint_name
+	and fk.constraint_type = 'foreign key'
 
-JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS PK 
-	ON REF_CONST.UNIQUE_CONSTRAINT_CATALOG = PK.CONSTRAINT_CATALOG
-	AND REF_CONST.UNIQUE_CONSTRAINT_SCHEMA = PK.CONSTRAINT_SCHEMA
-	AND REF_CONST.UNIQUE_CONSTRAINT_NAME = PK.CONSTRAINT_NAME
-	AND PK.CONSTRAINT_TYPE = 'PRIMARY KEY'
+join information_schema.table_constraints pk 
+	on ref_const.unique_constraint_catalog = pk.constraint_catalog
+	and ref_const.unique_constraint_schema = pk.constraint_schema
+	and ref_const.unique_constraint_name = pk.constraint_name
+	and pk.constraint_type = 'primary key'
 
-JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE FK_COLS 
-	ON REF_CONST.CONSTRAINT_NAME = FK_COLS.CONSTRAINT_NAME
+join information_schema.key_column_usage fk_cols 
+	on ref_const.constraint_name = fk_cols.constraint_name
 
-JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE PK_COLS 
-	ON PK.CONSTRAINT_NAME = PK_COLS.CONSTRAINT_NAME
+join information_schema.key_column_usage pk_cols 
+	on pk.constraint_name = pk_cols.constraint_name
 where
-	FK.TABLE_NAME = %s"""
+	fk.table_name = %s"""
         cursor.execute(sql,[table_name])
         relations = cursor.fetchall()
         relation_map = dict()
         indexes = dict()
         
         for column_name, unique, primary_key in constraints:
-            column_name = column_name.lower()
-            indexes[column_name] = {"primary_key":primary_key, "unique":unique}
+            indexes[column_name.lower()] = {"primary_key":primary_key, "unique":unique}
         
         return indexes
-        
-    
+
+
     data_types_reverse = {
         ado_consts.AUTO_FIELD_MARKER: 'AutoField',
         ado_consts.adBoolean: 'BooleanField',
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.