Skip to content

Commit

Permalink
Support and enable SQLAlchemy 1.4 statement cache
Browse files Browse the repository at this point in the history
  • Loading branch information
jarus committed Jun 11, 2022
1 parent 064425c commit eeb6dc8
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions sqlalchemy_hana/dialect.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from functools import wraps

import sqlalchemy
from sqlalchemy import sql, types, util
from sqlalchemy.engine import default, reflection
from sqlalchemy.sql import compiler
Expand Down Expand Up @@ -50,15 +51,15 @@ def visit_bindparam(self, bindparam, **kwargs):
# SAP HANA supports bindparameters within the columns clause of SELECT statements
# but it will always treat such columns as NVARCHAR(5000).
# With the effect that "select([literal(1)])" will return the string '1' instead of
# an interger. Therefore the following special logic for detecting such requests
# and rewriting the bindparam into a normal literal.
# an integer.
# The following logic detects such requests and rewriting the bindparam into a literal.

if kwargs.get("within_columns_clause") and kwargs.get("within_label_clause"):
if bindparam.value and bindparam.callable is None and not getattr(bindparam, "expanding", False):
return self.render_literal_bindparam(
bindparam, **kwargs
)

if sqlalchemy.__version__.startswith("1.3"):
return super(HANAStatementCompiler, self).visit_bindparam(bindparam, literal_binds=True)
else:
return super(HANAStatementCompiler, self).visit_bindparam(bindparam, literal_execute=True)
return super(HANAStatementCompiler, self).visit_bindparam(bindparam, **kwargs)

def visit_sequence(self, seq, **kwargs):
Expand Down Expand Up @@ -701,7 +702,7 @@ class HANAHDBCLIDialect(HANABaseDialect):
driver = 'hdbcli'
default_paramstyle = 'qmark'

supports_statement_cache = False
supports_statement_cache = True

@classmethod
def dbapi(cls):
Expand Down

0 comments on commit eeb6dc8

Please sign in to comment.