Skip to content

Commit 77e2d4c

Browse files
feat: Use adapter for WHERE clause generation (Phase 6 Part 2)
Update condition.py to use database adapter for backend-agnostic SQL: - Get adapter at start of make_condition() function - Update column identifier quoting (line 311) - Update subquery field list quoting (line 418) - WHERE clauses now properly quoted for both MySQL and PostgreSQL Maintains backward compatibility with MySQL backend. All existing tests pass. Part of Phase 6: Multi-backend PostgreSQL support. Related: #1338 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 1365bf9 commit 77e2d4c

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/datajoint/condition.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -301,11 +301,14 @@ def make_condition(
301301
"""
302302
from .expression import Aggregation, QueryExpression, U
303303

304+
# Get adapter for backend-agnostic SQL generation
305+
adapter = query_expression.connection.adapter
306+
304307
def prep_value(k, v):
305308
"""prepare SQL condition"""
306309
key_match, k = translate_attribute(k)
307310
if key_match["path"] is None:
308-
k = f"`{k}`"
311+
k = adapter.quote_identifier(k)
309312
if query_expression.heading[key_match["attr"]].json and key_match["path"] is not None and isinstance(v, dict):
310313
return f"{k}='{json.dumps(v)}'"
311314
if v is None:
@@ -410,10 +413,12 @@ def combine_conditions(negate, conditions):
410413
# without common attributes, any non-empty set matches everything
411414
(not negate if condition else negate)
412415
if not common_attributes
413-
else "({fields}) {not_}in ({subquery})".format(
414-
fields="`" + "`,`".join(common_attributes) + "`",
415-
not_="not " if negate else "",
416-
subquery=condition.make_sql(common_attributes),
416+
else (
417+
"({fields}) {not_}in ({subquery})".format(
418+
fields=", ".join(adapter.quote_identifier(a) for a in common_attributes),
419+
not_="not " if negate else "",
420+
subquery=condition.make_sql(common_attributes),
421+
)
417422
)
418423
)
419424

0 commit comments

Comments
 (0)