summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/compiler.py
diff options
context:
space:
mode:
authormike bayer <mike_mp@zzzcomputing.com>2022-06-01 16:13:36 +0000
committerGerrit Code Review <gerrit@ci3.zzzcomputing.com>2022-06-01 16:13:36 +0000
commit7b6fb299bb6b47dfeb22a5650b95af7fa0b35ec2 (patch)
tree84d683a496c9951838adb4efc09687f7c55b05af /lib/sqlalchemy/sql/compiler.py
parent79dbe94bb4ccd75888d57f388195a3ba4fa6117e (diff)
parent349a7c5e0e2aeeac98fad789b0043a4bdfeed837 (diff)
downloadsqlalchemy-7b6fb299bb6b47dfeb22a5650b95af7fa0b35ec2.tar.gz
Merge "add backend agnostic UUID datatype" into main
Diffstat (limited to 'lib/sqlalchemy/sql/compiler.py')
-rw-r--r--lib/sqlalchemy/sql/compiler.py45
1 files changed, 32 insertions, 13 deletions
diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py
index 12a598717..3685751b0 100644
--- a/lib/sqlalchemy/sql/compiler.py
+++ b/lib/sqlalchemy/sql/compiler.py
@@ -3013,14 +3013,14 @@ class SQLCompiler(Compiled):
def bindparam_string(
self,
- name,
- positional_names=None,
- post_compile=False,
- expanding=False,
- escaped_from=None,
- bindparam_type=None,
- **kw,
- ):
+ name: str,
+ positional_names: Optional[List[str]] = None,
+ post_compile: bool = False,
+ expanding: bool = False,
+ escaped_from: Optional[str] = None,
+ bindparam_type: Optional[TypeEngine[Any]] = None,
+ **kw: Any,
+ ) -> str:
if self.positional:
if positional_names is not None:
@@ -3045,9 +3045,23 @@ class SQLCompiler(Compiled):
{escaped_from: name}
)
if post_compile:
- return "__[POSTCOMPILE_%s]" % name
-
- ret = self.bindtemplate % {"name": name}
+ ret = "__[POSTCOMPILE_%s]" % name
+ if expanding:
+ # for expanding, bound parameters or literal values will be
+ # rendered per item
+ return ret
+
+ # otherwise, for non-expanding "literal execute", apply
+ # bind casts as determined by the datatype
+ if bindparam_type is not None:
+ type_impl = bindparam_type._unwrapped_dialect_impl(
+ self.dialect
+ )
+ if type_impl.render_literal_cast:
+ ret = self.render_bind_cast(bindparam_type, type_impl, ret)
+ return ret
+ else:
+ ret = self.bindtemplate % {"name": name}
if (
bindparam_type is not None
@@ -5432,10 +5446,12 @@ class GenericTypeCompiler(TypeCompiler):
def visit_NCLOB(self, type_, **kw):
return "NCLOB"
- def _render_string_type(self, type_, name):
+ def _render_string_type(self, type_, name, length_override=None):
text = name
- if type_.length:
+ if length_override:
+ text += "(%d)" % length_override
+ elif type_.length:
text += "(%d)" % type_.length
if type_.collation:
text += ' COLLATE "%s"' % type_.collation
@@ -5468,6 +5484,9 @@ class GenericTypeCompiler(TypeCompiler):
def visit_BOOLEAN(self, type_, **kw):
return "BOOLEAN"
+ def visit_uuid(self, type_, **kw):
+ return self._render_string_type(type_, "CHAR", length_override=32)
+
def visit_large_binary(self, type_, **kw):
return self.visit_BLOB(type_, **kw)