From 7a344ce76339170f4bba74a3658677790f05736d Mon Sep 17 00:00:00 2001 From: Dmitry Maslennikov Date: Mon, 14 Nov 2022 15:34:14 +0400 Subject: [PATCH] workaround for delete all with foreign keys --- sqlalchemy_iris/base.py | 15 +++++++++++++++ sqlalchemy_iris/requirements.py | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/sqlalchemy_iris/base.py b/sqlalchemy_iris/base.py index 99e21d8..d2a12ec 100644 --- a/sqlalchemy_iris/base.py +++ b/sqlalchemy_iris/base.py @@ -348,6 +348,21 @@ def _get_limit_or_fetch(self, select): else: return select._fetch_clause + def visit_delete(self, delete_stmt, **kw): + if not delete_stmt._where_criteria and delete_stmt.table.foreign_keys: + # https://community.intersystems.com/post/sql-foreign-key-constraint-check-delete + table = delete_stmt.table + nocheck = False + for fk in table.foreign_keys: + nocheck = not fk.ondelete and fk.parent.table == table + if not nocheck: + break + + if nocheck is True: + delete_stmt = delete_stmt.prefix_with('%NOCHECK', dialect='iris') + text = super().visit_delete(delete_stmt, **kw) + return text + def visit_true(self, expr, **kw): return "1" diff --git a/sqlalchemy_iris/requirements.py b/sqlalchemy_iris/requirements.py index 6f944af..d278ae4 100644 --- a/sqlalchemy_iris/requirements.py +++ b/sqlalchemy_iris/requirements.py @@ -93,3 +93,36 @@ def binary_literals(self): return exclusions.closed() + @property + def foreign_key_constraint_option_reflection_ondelete(self): + return exclusions.open() + + @property + def fk_constraint_option_reflection_ondelete_restrict(self): + return exclusions.closed() + + @property + def fk_constraint_option_reflection_ondelete_noaction(self): + return exclusions.open() + + @property + def foreign_key_constraint_option_reflection_onupdate(self): + return exclusions.open() + + @property + def fk_constraint_option_reflection_onupdate_restrict(self): + return exclusions.closed() + + + @property + def precision_numerics_many_significant_digits(self): + """target backend supports values with many digits on both sides, + such as 319438950232418390.273596, 87673.594069654243 + + """ + return exclusions.closed() + + @property + def symbol_names_w_double_quote(self): + """Target driver can create tables with a name like 'some " table'""" + return exclusions.closed()