From: Mike Bayer Date: Sat, 25 Jan 2014 21:55:27 +0000 (-0500) Subject: tweak text X-Git-Tag: rel_0_8_5~37 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7680ba30eb222632fc4cbf0a499cce514295c3bc;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git tweak text --- diff --git a/lib/sqlalchemy/sql/expression.py b/lib/sqlalchemy/sql/expression.py index d5f53a2605..6e43387126 100644 --- a/lib/sqlalchemy/sql/expression.py +++ b/lib/sqlalchemy/sql/expression.py @@ -1543,6 +1543,11 @@ def text(text, bind=None, *args, **kwargs): t = text("SELECT * FROM users WHERE id=:user_id") result = connection.execute(t, user_id=12) + For SQL statements where a colon is required verbatim, as within + an inline string, use a backslash to escape:: + + t = text("SELECT * FROM users WHERE name='\\:username'") + To invoke SQLAlchemy typing logic for bind parameters, the ``bindparams`` list allows specification of :func:`bindparam` constructs which specify the type for a given name:: @@ -1564,10 +1569,10 @@ def text(text, bind=None, *args, **kwargs): } ) - The :func:`text` construct is used internally for most cases when + The :func:`.text` construct is used internally for most cases when a literal string is specified for part of a larger query, such as - within :func:`select()`, :func:`update()`, - :func:`insert()` or :func:`delete()`. In those cases, the same + within :func:`.select()`, :func:`.update()`, + :func:`.insert()` or :func:`.delete()`. In those cases, the same bind parameter syntax is applied:: s = select([users.c.id, users.c.name]).where("id=:user_id") @@ -1578,7 +1583,8 @@ def text(text, bind=None, *args, **kwargs): to it as an :class:`.Executable` object, and it supports the :meth:`Executable.execution_options` method. For example, a :func:`text` construct that should be subject to "autocommit" - can be set explicitly so using the ``autocommit`` option:: + can be set explicitly so using the :paramref:`.Connection.execution_options.autocommit` + option:: t = text("EXEC my_procedural_thing()").\\ execution_options(autocommit=True)