Optimized Oracle PKs introspection by adding get_primary_key_column().

This commit is contained in:
Mariusz Felisiak 2019-01-18 16:50:06 +01:00 committed by GitHub
parent fe6d5a2da2
commit 709a8b861d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 0 deletions

View File

@ -173,6 +173,22 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
for row in cursor.fetchall()
]
def get_primary_key_column(self, cursor, table_name):
cursor.execute("""
SELECT
cols.column_name
FROM
user_constraints,
user_cons_columns cols
WHERE
user_constraints.constraint_name = cols.constraint_name AND
user_constraints.constraint_type = 'P' AND
user_constraints.table_name = UPPER(%s) AND
cols.position = 1
""", [table_name])
row = cursor.fetchone()
return self.identifier_converter(row[0]) if row else None
def get_constraints(self, cursor, table_name):
"""
Retrieve any constraints or keys (unique, pk, fk, check, index) across