Skip to content

Commit dfec805

Browse files
committed
explicit cast for case statement in 2023.1
1 parent dbcaac4 commit dfec805

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

sqlalchemy_iris/base.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,30 @@ def visit_not_regexp_match_op_binary(self, binary, operator, **kw):
526526
# InterSystems use own format for %MATCHES, it does not support Regular Expressions
527527
raise exc.CompileError("InterSystems IRIS does not support REGEXP")
528528

529+
def visit_case(self, clause, **kwargs):
530+
x = "CASE "
531+
if clause.value is not None:
532+
x += clause.value._compiler_dispatch(self, **kwargs) + " "
533+
for cond, result in clause.whens:
534+
x += (
535+
"WHEN "
536+
+ cond._compiler_dispatch(self, **kwargs)
537+
+ " THEN "
538+
# Explicit CAST required on 2023.1
539+
+ (self.visit_cast(sql.cast(result, result.type), **kwargs)
540+
if isinstance(result, sql.elements.BindParameter) else result._compiler_dispatch(self, **kwargs))
541+
+ " "
542+
)
543+
if clause.else_ is not None:
544+
x += (
545+
"ELSE "
546+
+ (self.visit_cast(sql.cast(clause.else_, clause.else_.type), **kwargs)
547+
if isinstance(clause.else_, sql.elements.BindParameter) else clause.else_._compiler_dispatch(self, **kwargs))
548+
+ " "
549+
)
550+
x += "END"
551+
return x
552+
529553

530554
class IRISDDLCompiler(sql.compiler.DDLCompiler):
531555
"""IRIS syntactic idiosyncrasies"""
@@ -850,15 +874,15 @@ def create_connect_args(self, url):
850874
opts["autoCommit"] = False
851875

852876
opts["embedded"] = self.embedded
853-
if "@" in opts["hostname"]:
877+
if opts["hostname"] and "@" in opts["hostname"]:
854878
_h = opts["hostname"].split("@")
855-
opts["password"] += "@" + _h[0 : len(_h) - 1].join("@")
879+
opts["password"] += "@" + _h[0: len(_h) - 1].join("@")
856880
opts["hostname"] = _h[len(_h) - 1]
857881

858882
return ([], opts)
859883

860884
_debug_queries = False
861-
# _debug_queries = True
885+
_debug_queries = True
862886

863887
def _debug(self, query, params, many=False):
864888
from decimal import Decimal

0 commit comments

Comments
 (0)