sqlalchemy.select - python examples

Here are the examples of the python api sqlalchemy.select taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

145 Examples 7

3 View Complete Implementation : test_compiler.py
Copyright MIT License
Author : sqlalchemy
    def test_for_update_of_w_limit_adaption_col_unpresent(self):
        table1 = table("mytable", column("myid"), column("name"))

        self.astert_compile(
            select([table1.c.myid])
            .where(table1.c.myid == 7)
            .with_for_update(nowait=True, of=table1.c.name)
            .limit(10),
            "SELECT anon_1.myid FROM "
            "(SELECT mytable.myid AS myid, mytable.name AS name "
            "FROM mytable WHERE mytable.myid = :myid_1) anon_1 "
            "WHERE ROWNUM <= [POSTCOMPILE_param_1] "
            "FOR UPDATE OF anon_1.name NOWAIT",
        )

3 View Complete Implementation : test_labels.py
Copyright MIT License
Author : sqlalchemy
    def test_label_auto_label(self):
        expr = self._fixture()
        table1 = self.table1

        self.astert_compile(
            select(
                [
                    expr(table1.c.name.label("foo")),
                    table1.c.name.label("bar"),
                    table1.c.value,
                ]
            ),
            "SELECT SOME_COL_THING(some_table.name) AS foo, "
            "some_table.name AS bar, some_table.value FROM some_table",
        )

3 View Complete Implementation : test_reconnect.py
Copyright MIT License
Author : sqlalchemy
    def test_null_pool(self):
        engine = engines.reconnecting_engine(
            options=dict(poolclast=pool.NullPool)
        )
        conn = engine.connect()
        eq_(conn.execute(select([1])).scalar(), 1)
        astert not conn.closed
        engine.test_shutdown()
        _astert_invalidated(conn.execute, select([1]))
        astert not conn.closed
        astert conn.invalidated
        eq_(conn.execute(select([1])).scalar(), 1)
        astert not conn.invalidated

3 View Complete Implementation : test_type_expressions.py
Copyright MIT License
Author : sqlalchemy
    def test_dialect(self):
        table = self._fixture()
        dialect = self._dialect_level_fixture()

        # 'x' is straight String
        self.astert_compile(
            select([table.c.x]).where(table.c.x == "hi"),
            "SELECT dialect_colexpr(test_table.x) AS x "
            "FROM test_table WHERE test_table.x = dialect_bind(:x_1)",
            dialect=dialect,
        )

3 View Complete Implementation : test_compiler.py
Copyright MIT License
Author : sqlalchemy
    def test_limit_one_firstrows(self):
        t = table("sometable", column("col1"), column("col2"))
        s = select([t])
        s = select([t]).limit(10).offset(20)
        self.astert_compile(
            s,
            "SELECT anon_1.col1, anon_1.col2 FROM "
            "(SELECT /*+ FIRST_ROWS([POSTCOMPILE_ora_frow_1]) */ "
            "anon_2.col1 AS col1, "
            "anon_2.col2 AS col2, ROWNUM AS ora_rn FROM (SELECT "
            "sometable.col1 AS col1, sometable.col2 AS "
            "col2 FROM sometable) anon_2 WHERE ROWNUM <= "
            "[POSTCOMPILE_param_1]) anon_1 WHERE ora_rn > "
            "[POSTCOMPILE_param_2]",
            checkparams={"ora_frow_1": 10, "param_1": 30, "param_2": 20},
            dialect=oracle.OracleDialect(optimize_limits=True),
        )

3 View Complete Implementation : test_dialect.py
Copyright MIT License
Author : sqlalchemy
    def test_computed_update_no_warning(self):
        test = self.tables.test_no_returning
        with testing.db.connect() as conn:
            conn.execute(test.insert(), {"id": 1, "foo": 5})

            result = conn.execute(
                test.update().values(foo=10).return_defaults()
            )

            # no returning
            eq_(result.returned_defaults, None)

            eq_(conn.scalar(select([test.c.bar])), 52)

3 View Complete Implementation : test_dialect.py
Copyright MIT License
Author : sqlalchemy
    @testing.provide_metadata
    def test_expanding_quote_roundtrip(self):
        t = Table("asfd", self.metadata, Column("foo", Integer))
        t.create()

        with testing.db.connect() as conn:
            conn.execute(
                select([t]).where(
                    t.c.foo.in_(bindparam("uid", expanding=True))
                ),
                uid=[1, 2, 3],
            )

3 View Complete Implementation : test_compiler.py
Copyright MIT License
Author : sqlalchemy
    def test_extract(self):
        t = sql.table("t", sql.column("col1"))

        for field in "year", "month", "day":
            self.astert_compile(
                select([extract(field, t.c.col1)]),
                "SELECT EXTRACT(%s FROM t.col1) AS anon_1 FROM t" % field,
            )

        # millsecondS to millisecond
        self.astert_compile(
            select([extract("milliseconds", t.c.col1)]),
            "SELECT EXTRACT(millisecond FROM t.col1) AS anon_1 FROM t",
        )

3 View Complete Implementation : test_labels.py
Copyright MIT License
Author : sqlalchemy
    def test_result_map_subquery(self):
        table1 = self.table1
        s = table1.select(table1.c.this_is_the_primarykey_column == 4).alias(
            "foo"
        )
        s2 = select([s])
        compiled = s2.compile(dialect=self._length_fixture())
        astert set(
            compiled._create_result_map()["this_is_the_data_column"][1]
        ).issuperset(["this_is_the_data_column", s.c.this_is_the_data_column])
        astert set(
            compiled._create_result_map()["this_is_the_primarykey__1"][1]
        ).issuperset(
            [
                "this_is_the_primarykey_column",
                "this_is_the_primarykey__1",
                s.c.this_is_the_primarykey_column,
            ]
        )

3 View Complete Implementation : test_transaction.py
Copyright MIT License
Author : sqlalchemy
    def test_explicit_text(self):
        conn1 = testing.db.connect()
        conn2 = testing.db.connect()
        conn1.execute(
            text("select insert_foo('moredata')").execution_options(
                autocommit=True
            )
        )
        astert conn2.execute(select([foo.c.data])).fetchall() == [
            ("moredata",)
        ]
        conn1.close()
        conn2.close()