From: Mike Bayer Date: Fri, 23 May 2014 18:26:22 +0000 (-0400) Subject: - document the compiler_kwargs accessor X-Git-Tag: rel_1_0_0b1~431 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=bc91884a4125ebda230ae8ff20f2af1dbc7e63c6;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - document the compiler_kwargs accessor - add new FAQ for rendering SQL as a string --- diff --git a/doc/build/faq.rst b/doc/build/faq.rst index a1753bbcc0..8862cac954 100644 --- a/doc/build/faq.rst +++ b/doc/build/faq.rst @@ -243,6 +243,107 @@ techniques can be seen at `Naming Conventions `:: + + from sqlalchemy.ext.compiler import compiles + from sqlalchemy.sql.expression import BindParameter + + s = select([t]).where(t.c.x == 5) + + @compiles(BindParameter) + def as_str(element, compiler, **kw): + if 'binds_as_str' in kw: + return str(element.effective_value) + else: + return compiler.visit_bindparam(element, **kw) + + print s.compile(compile_kwargs={"binds_as_str": True}) + +Above, we pass a self-defined flag ``binds_as_str`` through the compiler, +which we then intercept within our custom render method for :class:`.BindParameter`. + Why does ``.col.in_([])`` Produce ``col != col``? Why not ``1=0``? ------------------------------------------------------------------- diff --git a/lib/sqlalchemy/sql/elements.py b/lib/sqlalchemy/sql/elements.py index 9f08aea671..13cf9aa918 100644 --- a/lib/sqlalchemy/sql/elements.py +++ b/lib/sqlalchemy/sql/elements.py @@ -460,6 +460,26 @@ class ClauseElement(Visitable): also refer to any server-side default generation function associated with a primary key `Column`. + :param compile_kwargs: optional dictionary of additional parameters + that will be passed through to the compiler within all "visit" + methods. This allows any custom flag to be passed through to + a custom compilation construct, for example. It is also used + for the case of passing the ``literal_binds`` flag through:: + + from sqlalchemy.sql import table, column, select + + t = table('t', column('x')) + + s = select([t]).where(t.c.x == 5) + + print s.compile(compile_kwargs={"literal_binds": True}) + + .. versionadded:: 0.9.0 + + .. seealso:: + + :ref:`faq_sql_expression_string` + """ if not dialect: