当前位置: 首页>>代码示例>>Python>>正文


Python util.u方法代码示例

本文整理汇总了Python中sqlalchemy.util.u方法的典型用法代码示例。如果您正苦于以下问题:Python util.u方法的具体用法?Python util.u怎么用?Python util.u使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sqlalchemy.util的用法示例。


在下文中一共展示了util.u方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_insert

# 需要导入模块: from sqlalchemy import util [as 别名]
# 或者: from sqlalchemy.util import u [as 别名]
def test_insert(self, connection):
        connection.execute(t1.insert(), {u("méil"): 1, ue("\u6e2c\u8a66"): 5})
        connection.execute(t2.insert(), {u("a"): 1, u("b"): 1})
        connection.execute(
            t3.insert(),
            {
                ue("\u6e2c\u8a66_id"): 1,
                ue("unitable1_\u6e2c\u8a66"): 5,
                u("Unitéble2_b"): 1,
                ue("\u6e2c\u8a66_self"): 1,
            },
        )

        eq_(connection.execute(t1.select()).fetchall(), [(1, 5)])
        eq_(connection.execute(t2.select()).fetchall(), [(1, 1)])
        eq_(connection.execute(t3.select()).fetchall(), [(1, 5, 1, 1)]) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:18,代码来源:test_unicode_ddl.py

示例2: test_exception_wrapping_non_dbapi_statement

# 需要导入模块: from sqlalchemy import util [as 别名]
# 或者: from sqlalchemy.util import u [as 别名]
def test_exception_wrapping_non_dbapi_statement(self):
        class MyType(TypeDecorator):
            impl = Integer

            def process_bind_param(self, value, dialect):
                raise SomeException("nope")

        def _go(conn):
            assert_raises_message(
                tsa.exc.StatementError,
                r"\(.*.SomeException\) " r"nope\n\[SQL\: u?SELECT 1 ",
                conn.execute,
                select([1]).where(column("foo") == literal("bar", MyType())),
            )

        _go(testing.db)
        with testing.db.connect() as conn:
            _go(conn) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:20,代码来源:test_execute.py

示例3: test_stmt_exception_bytestring_raised

# 需要导入模块: from sqlalchemy import util [as 别名]
# 或者: from sqlalchemy.util import u [as 别名]
def test_stmt_exception_bytestring_raised(self):
        name = util.u("méil")
        with testing.db.connect() as conn:
            assert_raises_message(
                tsa.exc.StatementError,
                util.u(
                    "A value is required for bind parameter 'uname'\n"
                    r".*SELECT users.user_name AS .m\xe9il."
                )
                if util.py2k
                else util.u(
                    "A value is required for bind parameter 'uname'\n"
                    ".*SELECT users.user_name AS .méil."
                ),
                conn.execute,
                select([users.c.user_name.label(name)]).where(
                    users.c.user_name == bindparam("uname")
                ),
                {"uname_incorrect": "foo"},
            ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:22,代码来源:test_execute.py

示例4: test_reflect_unicode_no_nvarchar

# 需要导入模块: from sqlalchemy import util [as 别名]
# 或者: from sqlalchemy.util import u [as 别名]
def test_reflect_unicode_no_nvarchar(self):
        metadata = self.metadata
        Table("tnv", metadata, Column("data", sqltypes.Unicode(255)))
        metadata.create_all()
        m2 = MetaData(testing.db)
        t2 = Table("tnv", m2, autoload=True)
        assert isinstance(t2.c.data.type, sqltypes.VARCHAR)

        if testing.against("oracle+cx_oracle"):
            assert isinstance(
                t2.c.data.type.dialect_impl(testing.db.dialect),
                cx_oracle._OracleString,
            )

        data = u("m’a réveillé.")
        t2.insert().execute(data=data)
        res = t2.select().execute().first()["data"]
        eq_(res, data)
        assert isinstance(res, util.text_type) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:21,代码来源:test_types.py

示例5: test_unicode_round_trip

# 需要导入模块: from sqlalchemy import util [as 别名]
# 或者: from sqlalchemy.util import u [as 别名]
def test_unicode_round_trip(self, connection):
        s = select(
            [
                cast(
                    {
                        util.u("réveillé"): util.u("réveillé"),
                        "data": {"k1": util.u("drôle")},
                    },
                    self.test_type,
                )
            ]
        )
        eq_(
            connection.scalar(s),
            {
                util.u("réveillé"): util.u("réveillé"),
                "data": {"k1": util.u("drôle")},
            },
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:21,代码来源:test_types.py

示例6: define_tables

# 需要导入模块: from sqlalchemy import util [as 别名]
# 或者: from sqlalchemy.util import u [as 别名]
def define_tables(cls, metadata):
        Table(
            "data",
            metadata,
            Column("id", Integer, primary_key=True),
            Column("x", String),
            Column("y", String),
            Column("z", Integer, server_default="5"),
        )

        Table(
            u("Unitéble2"),
            metadata,
            Column(u("méil"), Integer, primary_key=True),
            Column(ue("\u6e2c\u8a66"), Integer),
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:18,代码来源:test_dialect.py

示例7: test_create_drop_enum

# 需要导入模块: from sqlalchemy import util [as 别名]
# 或者: from sqlalchemy.util import u [as 别名]
def test_create_drop_enum(self):
        # test escaping and unicode within CREATE TYPE for ENUM
        typ = postgresql.ENUM(
            "val1", "val2", "val's 3", u("méil"), name="myname"
        )
        self.assert_compile(
            postgresql.CreateEnumType(typ),
            u(
                "CREATE TYPE myname AS "
                "ENUM ('val1', 'val2', 'val''s 3', 'méil')"
            ),
        )

        typ = postgresql.ENUM("val1", "val2", "val's 3", name="PleaseQuoteMe")
        self.assert_compile(
            postgresql.CreateEnumType(typ),
            'CREATE TYPE "PleaseQuoteMe" AS ENUM '
            "('val1', 'val2', 'val''s 3')",
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:21,代码来源:test_compiler.py

示例8: test_charset_collate_table

# 需要导入模块: from sqlalchemy import util [as 别名]
# 或者: from sqlalchemy.util import u [as 别名]
def test_charset_collate_table(self):
        t = Table(
            "foo",
            self.metadata,
            Column("id", Integer),
            Column("data", UnicodeText),
            mysql_default_charset="utf8",
            mysql_collate="utf8_bin",
        )
        t.create()
        m2 = MetaData(testing.db)
        t2 = Table("foo", m2, autoload=True)
        eq_(t2.kwargs["mysql_collate"], "utf8_bin")
        eq_(t2.kwargs["mysql_default charset"], "utf8")

        # test [ticket:2906]
        # in order to test the condition here, need to use
        # MySQLdb 1.2.3 and also need to pass either use_unicode=1
        # or charset=utf8 to the URL.
        t.insert().execute(id=1, data=u("some text"))
        assert isinstance(
            testing.db.scalar(select([t.c.data])), util.text_type
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:25,代码来源:test_types.py

示例9: test_unicode_roundtrip

# 需要导入模块: from sqlalchemy import util [as 别名]
# 或者: from sqlalchemy.util import u [as 别名]
def test_unicode_roundtrip(self):
        set_table = Table(
            "t",
            self.metadata,
            Column("id", Integer, primary_key=True),
            Column("data", mysql.SET(u("réveillé"), u("drôle"), u("S’il"))),
        )

        set_table.create()
        with testing.db.begin() as conn:
            conn.execute(
                set_table.insert(), {"data": set([u("réveillé"), u("drôle")])}
            )

            row = conn.execute(set_table.select()).first()

            eq_(row, (1, set([u("réveillé"), u("drôle")]))) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:19,代码来源:test_types.py

示例10: _bug_88718_96365_casing_1

# 需要导入模块: from sqlalchemy import util [as 别名]
# 或者: from sqlalchemy.util import u [as 别名]
def _bug_88718_96365_casing_1(self):
        fkeys_casing_1 = [
            {
                "name": "FK_PlaylistTTrackId",
                "constrained_columns": ["TTrackID"],
                "referred_schema": "Test_Schema",
                "referred_table": "Track",
                "referred_columns": ["trackid"],
                "options": {},
            },
            {
                "name": "FK_PlaylistTrackId",
                "constrained_columns": ["TrackID"],
                "referred_schema": None,
                "referred_table": "Track",
                "referred_columns": ["trackid"],
                "options": {},
            },
        ]
        ischema_casing_1 = [
            (util.u("Test"), util.u("Track"), "TrackID"),
            (util.u("Test_Schema"), util.u("Track"), "TrackID"),
        ]
        return fkeys_casing_1, ischema_casing_1 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:26,代码来源:test_reflection.py

示例11: define_tables

# 需要导入模块: from sqlalchemy import util [as 别名]
# 或者: from sqlalchemy.util import u [as 别名]
def define_tables(cls, metadata):
        Table(
            "q",
            metadata,
            Column("x", Integer, default=2),
            Column("y", Integer, onupdate=5),
            Column("z", Integer),
        )

        Table(
            "p",
            metadata,
            Column("s", Integer),
            Column("t", Integer),
            Column("u", Integer, onupdate=1),
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:18,代码来源:test_defaults.py

示例12: test_list_assignment_new

# 需要导入模块: from sqlalchemy import util [as 别名]
# 或者: from sqlalchemy.util import u [as 别名]
def test_list_assignment_new(self):
        User, Order = self.classes.User, self.classes.Order

        sess = Session()
        u = User(
            name="jack",
            orders=[
                Order(description="order 1"),
                Order(description="order 2"),
            ],
        )
        sess.add(u)
        sess.commit()

        eq_(
            u,
            User(
                name="jack",
                orders=[
                    Order(description="order 1"),
                    Order(description="order 2"),
                ],
            ),
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:26,代码来源:test_cascade.py

示例13: test_remove_pending_from_pending_parent

# 需要导入模块: from sqlalchemy import util [as 别名]
# 或者: from sqlalchemy.util import u [as 别名]
def test_remove_pending_from_pending_parent(self):
        # test issue #4040

        User, Order = self.classes.User, self.classes.Order

        sess = Session()

        u = User(name="jack")

        o1 = Order()
        sess.add(o1)

        # object becomes an orphan, but parent is not in session
        u.orders.append(o1)
        u.orders.remove(o1)

        sess.add(u)

        assert o1 in sess

        sess.flush()

        assert o1 not in sess 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:25,代码来源:test_cascade.py

示例14: test_delete

# 需要导入模块: from sqlalchemy import util [as 别名]
# 或者: from sqlalchemy.util import u [as 别名]
def test_delete(self):
        User, users, orders, Order = (
            self.classes.User,
            self.tables.users,
            self.tables.orders,
            self.classes.Order,
        )

        sess = create_session()
        u = User(
            name="jack",
            orders=[
                Order(description="someorder"),
                Order(description="someotherorder"),
            ],
        )
        sess.add(u)
        sess.flush()

        sess.delete(u)
        sess.flush()
        eq_(select([func.count("*")]).select_from(users).scalar(), 0)
        eq_(select([func.count("*")]).select_from(orders).scalar(), 0) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:25,代码来源:test_cascade.py

示例15: test_column_prefix

# 需要导入模块: from sqlalchemy import util [as 别名]
# 或者: from sqlalchemy.util import u [as 别名]
def test_column_prefix(self):
        users, User = self.tables.users, self.classes.User

        mapper(
            User,
            users,
            column_prefix="_",
            properties={"user_name": synonym("_name")},
        )

        s = create_session()
        u = s.query(User).get(7)
        eq_(u._name, "jack")
        eq_(u._id, 7)
        u2 = s.query(User).filter_by(user_name="jack").one()
        assert u is u2 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:18,代码来源:test_mapper.py


注:本文中的sqlalchemy.util.u方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。