Regarding the following:
> if the type of the LiteralBindParameter implements “literal_processor()”,
> that controls how the literal value is rendered into the statement.
How does one implement the "literal_processor()" for a new type? Is
literal_processor() method applicable for UserDefinedTypes?
----- Original Message -----
...
Is there a way to render a udt like class into literal part of query rather
than binding it as a parameter?
there is, but it would kind of disqualify this as something we can add to
SQLAlchemy directly b.c. it’s basically a security hazard (as unlikely as it is
in this case).
essentially if the “literal_binds” flag is passed through to the compiler it
will render bound parameters inline. This flag can be set on a per-element
basis using the recipe below:
from sqlalchemy.sql.expression import BindParameter
from sqlalchemy.ext.compiler import compiles
class LiteralBindParam(BindParameter):
pass
@compiles(LiteralBindParam)
def literal_bind(element, compiler, **kw):
kw['literal_binds'] = True
return compiler.visit_bindparam(element, **kw)
from sqlalchemy.sql import select, column
stmt = select([column('x'), column('y')]).\
where(column('x') == 5).\
where(column('y') == LiteralBindParam(None, 7))
print stmt
will print:
SELECT x, y
WHERE x = :x_1 AND y = 7
from there, if the type of the LiteralBindParameter implements
“literal_processor()”, that controls how the literal value is rendered into the
statement.
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/groups/opt_out.