def get_pk_constraint(self, connection, table_name, schema=None, **kw):
"""
Override
TODO: Check if we need PRIMARY Indices or PRIMARY KEY Indices
TODO: Check for border cases (No PK Indices)
"""
if schema is None:
schema = self.default_schema_name
stmt = select([column('ColumnName'), column('IndexName')],
from_obj=[text('dbc.Indices')]).where(
and_(text('DatabaseName = :schema'),
text('TableName=:table'),
text('IndexType=:indextype'))
).order_by(asc(column('IndexNumber')))
# K for Primary Key
res = connection.execute(stmt, schema=schema, table=table_name, indextype='K').fetchall()
index_columns = list()
index_name = None
for index_column in res:
index_columns.append(self.normalize_name(index_column['ColumnName']))
index_name = self.normalize_name(index_column['IndexName']) # There should be just one IndexName
return {
"constrained_columns": index_columns,
"name": index_name
}
评论列表
文章目录