Python sqlalchemy.sql.elements.BindParameter() Examples

The following are 4 code examples of sqlalchemy.sql.elements.BindParameter(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module sqlalchemy.sql.elements , or try the search function .
Example #1
Source File: test_selectable.py    From sqlalchemy with MIT License 6 votes vote down vote up
def test_ensure_repr_elements(self):
        for obj in [
            elements.Cast(1, 2),
            elements.TypeClause(String()),
            elements.ColumnClause("x"),
            elements.BindParameter("q"),
            elements.Null(),
            elements.True_(),
            elements.False_(),
            elements.ClauseList(),
            elements.BooleanClauseList._construct_raw(operators.and_),
            elements.BooleanClauseList._construct_raw(operators.or_),
            elements.Tuple(),
            elements.Case([]),
            elements.Extract("foo", column("x")),
            elements.UnaryExpression(column("x")),
            elements.Grouping(column("x")),
            elements.Over(func.foo()),
            elements.Label("q", column("x")),
        ]:
            repr(obj) 
Example #2
Source File: test_compare.py    From sqlalchemy with MIT License 5 votes vote down vote up
def test_bindparam_subclass_nocache(self):
        # does not implement inherit_cache
        class _literal_bindparam(BindParameter):
            pass

        l1 = _literal_bindparam(None, value="x1")
        is_(l1._generate_cache_key(), None) 
Example #3
Source File: test_compare.py    From sqlalchemy with MIT License 5 votes vote down vote up
def test_bindparam_subclass_ok_cache(self):
        # implements inherit_cache
        class _literal_bindparam(BindParameter):
            inherit_cache = True

        def fixture():
            return (
                _literal_bindparam(None, value="x1"),
                _literal_bindparam(None, value="x2"),
                _literal_bindparam(None),
            )

        self._run_cache_key_fixture(fixture, True) 
Example #4
Source File: test_compare.py    From sqlalchemy with MIT License 4 votes vote down vote up
def _statements_w_anonymous_col_names():
        def one():
            c = column("q")

            l = c.label(None)

            # new case as of Id810f485c5f7ed971529489b84694e02a3356d6d
            subq = select([l]).subquery()

            # this creates a ColumnClause as a proxy to the Label() that has
            # an anoymous name, so the column has one too.
            anon_col = subq.c[0]

            # then when BindParameter is created, it checks the label
            # and doesn't double up on the anonymous name which is uncachable
            return anon_col > 5

        def two():
            c = column("p")

            l = c.label(None)

            # new case as of Id810f485c5f7ed971529489b84694e02a3356d6d
            subq = select([l]).subquery()

            # this creates a ColumnClause as a proxy to the Label() that has
            # an anoymous name, so the column has one too.
            anon_col = subq.c[0]

            # then when BindParameter is created, it checks the label
            # and doesn't double up on the anonymous name which is uncachable
            return anon_col > 5

        def three():

            l1, l2 = table_a.c.a.label(None), table_a.c.b.label(None)

            stmt = select([table_a.c.a, table_a.c.b, l1, l2])

            subq = stmt.subquery()
            return select([subq]).where(subq.c[2] == 10)

        return (
            one(),
            two(),
            three(),
        )