def test_skip_types(self, connection):
     connection.exec_driver_sql(
         "create table foo (id integer primary key, data xml)")
     with mock.patch.object(connection.dialect, "ischema_names",
                            {"int": mssql.INTEGER}):
         with testing.expect_warnings(
                 "Did not recognize type 'xml' of column 'data'"):
             eq_(
                 inspect(connection).get_columns("foo"),
                 [
                     {
                         "name": "id",
                         "type": testing.eq_type_affinity(sqltypes.INTEGER),
                         "nullable": False,
                         "default": None,
                         "autoincrement": False,
                     },
                     {
                         "name": "data",
                         "type": testing.eq_type_affinity(
                             sqltypes.NullType),
                         "nullable": True,
                         "default": None,
                         "autoincrement": False,
                     },
                 ],
             )
Beispiel #2
0
    def test_global_temp_different_collation(
        self, temp_db_alt_collation_fixture
    ):
        """test #8035"""

        tname = f"##foo{random.randint(1,1000000)}"

        with temp_db_alt_collation_fixture.connect() as conn:
            conn.exec_driver_sql(f"CREATE TABLE {tname} (id int primary key)")
            conn.commit()

            eq_(
                inspect(conn).get_columns(tname),
                [
                    {
                        "name": "id",
                        "type": testing.eq_type_affinity(sqltypes.INTEGER),
                        "nullable": False,
                        "default": None,
                        "autoincrement": False,
                        "comment": None,
                    }
                ],
            )
            Table(tname, MetaData(), autoload_with=conn)
Beispiel #3
0
    def test_returning_inspectable(self):
        t = table("t", column("x"), column("y"), column("z"))

        class HasClauseElement:
            def __clause_element__(self):
                return t

        stmt = update(HasClauseElement()).returning(HasClauseElement())

        eq_(
            stmt.returning_column_descriptions,
            [
                {
                    "name": "x",
                    "type": testing.eq_type_affinity(NullType),
                    "expr": t.c.x,
                },
                {
                    "name": "y",
                    "type": testing.eq_type_affinity(NullType),
                    "expr": t.c.y,
                },
                {
                    "name": "z",
                    "type": testing.eq_type_affinity(NullType),
                    "expr": t.c.z,
                },
            ],
        )

        self.assert_compile(
            stmt,
            "UPDATE t SET x=%(x)s, y=%(y)s, z=%(z)s "
            "RETURNING t.x, t.y, t.z",
        )
        cte = stmt.cte("c")

        stmt = select(cte.c.z)
        self.assert_compile(
            stmt,
            "WITH c AS (UPDATE t SET x=%(x)s, y=%(y)s, z=%(z)s "
            "RETURNING t.x, t.y, t.z) SELECT c.z FROM c",
        )
Beispiel #4
0
    def test_returning_fromclause(self):
        t = table("t", column("x"), column("y"), column("z"))
        stmt = t.update().returning(t)

        self.assert_compile(
            stmt,
            "UPDATE t SET x=%(x)s, y=%(y)s, z=%(z)s RETURNING t.x, t.y, t.z",
        )

        eq_(
            stmt.returning_column_descriptions,
            [
                {
                    "name": "x",
                    "type": testing.eq_type_affinity(NullType),
                    "expr": t.c.x,
                },
                {
                    "name": "y",
                    "type": testing.eq_type_affinity(NullType),
                    "expr": t.c.y,
                },
                {
                    "name": "z",
                    "type": testing.eq_type_affinity(NullType),
                    "expr": t.c.z,
                },
            ],
        )

        cte = stmt.cte("c")

        stmt = select(cte.c.z)
        self.assert_compile(
            stmt,
            "WITH c AS (UPDATE t SET x=%(x)s, y=%(y)s, z=%(z)s "
            "RETURNING t.x, t.y, t.z) SELECT c.z FROM c",
        )