summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/compiler.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2020-07-19 17:39:14 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2020-07-19 17:45:41 -0400
commit83b3ce6b7c7991d2faf314dc44571de9e6e9c27b (patch)
tree35e789e551aae9f15a2dd40a9ab66f38f0ba3cfb /lib/sqlalchemy/sql/compiler.py
parent547e959157f841f4f6d1e405ceed14755fcbd0bd (diff)
downloadsqlalchemy-83b3ce6b7c7991d2faf314dc44571de9e6e9c27b.tar.gz
Revise setinputsizes approach
in order to support asyncpg as well as pg8000, we need to revise setinputsizes to work for more cases as well as adjust NativeForEmulated a bit to work more completely with the INTERVAL datatype. - put most of the setinputsizes work into the compiler where the computation can be cached. - support per-element setinputsizes for a tuple - adjust TypeDecorator so that _unwrapped_dialect_impl will honor a type that the dialect links to directly in it's adaption mapping. Decouble _unwrapped_dialect_impl from TypeDecorator._gen_dialect_impl() which has a different purpose. This allows setinputsizes to do the right thing with the INTERVAL datatype. - test cases for Oracle with Variant continue to work Change-Id: I9e1ea33aeca3b92b365daa4a356d778191070c03
Diffstat (limited to 'lib/sqlalchemy/sql/compiler.py')
-rw-r--r--lib/sqlalchemy/sql/compiler.py63
1 files changed, 63 insertions, 0 deletions
diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py
index 3a3ce5c45..61e26b003 100644
--- a/lib/sqlalchemy/sql/compiler.py
+++ b/lib/sqlalchemy/sql/compiler.py
@@ -957,6 +957,68 @@ class SQLCompiler(Compiled):
pd[name] = value_param.value
return pd
+ @util.memoized_instancemethod
+ def _get_set_input_sizes_lookup(
+ self, translate=None, include_types=None, exclude_types=None
+ ):
+ if not hasattr(self, "bind_names"):
+ return None
+
+ dialect = self.dialect
+ dbapi = self.dialect.dbapi
+
+ # _unwrapped_dialect_impl() is necessary so that we get the
+ # correct dialect type for a custom TypeDecorator, or a Variant,
+ # which is also a TypeDecorator. Special types like Interval,
+ # that use TypeDecorator but also might be mapped directly
+ # for a dialect impl, also subclass Emulated first which overrides
+ # this behavior in those cases to behave like the default.
+
+ if not include_types and not exclude_types:
+
+ def _lookup_type(typ):
+ dialect_impl = typ._unwrapped_dialect_impl(dialect)
+ return dialect_impl.get_dbapi_type(dbapi)
+
+ else:
+
+ def _lookup_type(typ):
+ dialect_impl = typ._unwrapped_dialect_impl(dialect)
+ dbtype = dialect_impl.get_dbapi_type(dbapi)
+
+ if (
+ dbtype is not None
+ and (
+ not exclude_types
+ or dbtype not in exclude_types
+ and type(dialect_impl) not in exclude_types
+ )
+ and (
+ not include_types
+ or dbtype in include_types
+ or type(dialect_impl) in include_types
+ )
+ ):
+ return dbtype
+ else:
+ return None
+
+ inputsizes = {}
+ literal_execute_params = self.literal_execute_params
+
+ for bindparam in self.bind_names:
+ if bindparam in literal_execute_params:
+ continue
+
+ if bindparam._expanding_in_types:
+ inputsizes[bindparam] = [
+ _lookup_type(typ) for typ in bindparam._expanding_in_types
+ ]
+ else:
+ inputsizes[bindparam] = _lookup_type(bindparam.type)
+
+ return inputsizes
+
@property
def params(self):
"""Return the bind param dictionary embedded into this
@@ -4546,6 +4608,7 @@ class IdentifierPreparer(object):
if name is None:
name = table.name
+
result = self.quote(name)
effective_schema = self.schema_for_object(table)