Skip to content

Commit

Permalink
New method get_unique_constraints II-14372 (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
hab6 authored May 31, 2024
1 parent 033a879 commit 39ae514
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/sqlalchemy_ingres/_version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version_tuple = __version_info__ = (0, 0, 7, "dev4")
version_tuple = __version_info__ = (0, 0, 7, "dev5")
version = version_string = __version__ = '.'.join(map(str, __version_info__))
31 changes: 31 additions & 0 deletions lib/sqlalchemy_ingres/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,37 @@ def get_columns(self, connection, table_name, schema=None, **kw):
finally:
if rs:
rs.close()

@reflection.cache
def get_unique_constraints(self, connection, table_name, schema=None, **kw):
sqltext = """
SELECT
k.column_name
FROM
iikeys k,
iiconstraints c
WHERE
k.constraint_name = c.constraint_name
AND c.constraint_type = 'U'
AND k.table_name = ?"""
params = (self.denormalize_name(table_name),)

if schema:
sqltext += """
AND k.schema_name = ?"""
params = (*params, self.denormalize_name(schema))

rs = None

try:
rs = connection.exec_driver_sql(sqltext, params)

cols = [row[0].rstrip() for row in rs.fetchall()]
return {"constrained_columns": [] if cols is None else cols, "name": None}

finally:
if rs:
rs.close()

@reflection.cache
def get_primary_keys(self, connection, table_name, schema=None, **kw):
Expand Down

0 comments on commit 39ae514

Please sign in to comment.