Skip to content

Commit 7a344ce

Browse files
committed
workaround for delete all with foreign keys
1 parent 946a3bb commit 7a344ce

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

sqlalchemy_iris/base.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,21 @@ def _get_limit_or_fetch(self, select):
348348
else:
349349
return select._fetch_clause
350350

351+
def visit_delete(self, delete_stmt, **kw):
352+
if not delete_stmt._where_criteria and delete_stmt.table.foreign_keys:
353+
# https://community.intersystems.com/post/sql-foreign-key-constraint-check-delete
354+
table = delete_stmt.table
355+
nocheck = False
356+
for fk in table.foreign_keys:
357+
nocheck = not fk.ondelete and fk.parent.table == table
358+
if not nocheck:
359+
break
360+
361+
if nocheck is True:
362+
delete_stmt = delete_stmt.prefix_with('%NOCHECK', dialect='iris')
363+
text = super().visit_delete(delete_stmt, **kw)
364+
return text
365+
351366
def visit_true(self, expr, **kw):
352367
return "1"
353368

sqlalchemy_iris/requirements.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,36 @@ def binary_literals(self):
9393

9494
return exclusions.closed()
9595

96+
@property
97+
def foreign_key_constraint_option_reflection_ondelete(self):
98+
return exclusions.open()
99+
100+
@property
101+
def fk_constraint_option_reflection_ondelete_restrict(self):
102+
return exclusions.closed()
103+
104+
@property
105+
def fk_constraint_option_reflection_ondelete_noaction(self):
106+
return exclusions.open()
107+
108+
@property
109+
def foreign_key_constraint_option_reflection_onupdate(self):
110+
return exclusions.open()
111+
112+
@property
113+
def fk_constraint_option_reflection_onupdate_restrict(self):
114+
return exclusions.closed()
115+
116+
117+
@property
118+
def precision_numerics_many_significant_digits(self):
119+
"""target backend supports values with many digits on both sides,
120+
such as 319438950232418390.273596, 87673.594069654243
121+
122+
"""
123+
return exclusions.closed()
124+
125+
@property
126+
def symbol_names_w_double_quote(self):
127+
"""Target driver can create tables with a name like 'some " table'"""
128+
return exclusions.closed()

0 commit comments

Comments
 (0)