Skip to content

Commit

Permalink
workaround for delete all with foreign keys
Browse files Browse the repository at this point in the history
  • Loading branch information
daimor committed Nov 14, 2022
1 parent 946a3bb commit 7a344ce
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
15 changes: 15 additions & 0 deletions sqlalchemy_iris/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
33 changes: 33 additions & 0 deletions sqlalchemy_iris/requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 7a344ce

Please sign in to comment.