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


Python Table.select方法代码示例

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


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

示例1: test_passive_override

# 需要导入模块: from sqlalchemy.test.schema import Table [as 别名]
# 或者: from sqlalchemy.test.schema.Table import select [as 别名]
    def test_passive_override(self):
        """
        Primarily for postgres, tests that when we get a primary key column
        back from reflecting a table which has a default value on it, we
        pre-execute that DefaultClause upon insert, even though DefaultClause
        says "let the database execute this", because in postgres we must have
        all the primary key values in memory before insert; otherwise we can't
        locate the just inserted row.

        """
        # TODO: move this to dialect/postgres
        try:
            meta = MetaData(testing.db)
            testing.db.execute("""
             CREATE TABLE speedy_users
             (
                 speedy_user_id   SERIAL     PRIMARY KEY,

                 user_name        VARCHAR    NOT NULL,
                 user_password    VARCHAR    NOT NULL
             );
            """, None)

            t = Table("speedy_users", meta, autoload=True)
            t.insert().execute(user_name='user', user_password='lala')
            l = t.select().execute().fetchall()
            eq_(l, [(1, 'user', 'lala')])
        finally:
            testing.db.execute("drop table speedy_users", None)
开发者ID:gajop,项目名称:springgrid,代码行数:31,代码来源:test_defaults.py

示例2: test_direct_quoting

# 需要导入模块: from sqlalchemy.test.schema import Table [as 别名]
# 或者: from sqlalchemy.test.schema.Table import select [as 别名]
 def test_direct_quoting(self):
     m = MetaData(testing.db)
     t = Table("weird_casing", m, autoload=True)
     self.assert_compile(
         t.select(),
         'SELECT weird_casing.col1, weird_casing."Col2", weird_casing."col3" FROM weird_casing'
     )
开发者ID:clones,项目名称:sqlalchemy,代码行数:9,代码来源:test_reflection.py

示例3: test_empty_insert

# 需要导入模块: from sqlalchemy.test.schema import Table [as 别名]
# 或者: from sqlalchemy.test.schema.Table import select [as 别名]
 def test_empty_insert(self):
     metadata = MetaData(testing.db)
     t1 = Table('t1', metadata,
             Column('is_true', Boolean, server_default=('1')))
     metadata.create_all()
     
     try:
         result = t1.insert().execute()
         eq_(1, select([func.count(text('*'))], from_obj=t1).scalar())
         eq_(True, t1.select().scalar())
     finally:
         metadata.drop_all()
开发者ID:gajop,项目名称:springgrid,代码行数:14,代码来源:test_defaults.py

示例4: test_row_c_sequence_check

# 需要导入模块: from sqlalchemy.test.schema import Table [as 别名]
# 或者: from sqlalchemy.test.schema.Table import select [as 别名]
    def test_row_c_sequence_check(self):
        import csv
        import collections
        from StringIO import StringIO

        metadata = MetaData()
        metadata.bind = 'sqlite://'
        users = Table('users', metadata,
            Column('id', Integer, primary_key=True),
            Column('name', String(40)),
        )
        users.create()

        users.insert().execute(name='Test')
        row = users.select().execute().fetchone()

        s = StringIO()
        writer = csv.writer(s)
        # csv performs PySequenceCheck call
        writer.writerow(row)
        assert s.getvalue().strip() == '1,Test'
开发者ID:chatch,项目名称:pinyin-toolkit,代码行数:23,代码来源:test_execute.py

示例5: test_no_rowcount_on_selects_inserts

# 需要导入模块: from sqlalchemy.test.schema import Table [as 别名]
# 或者: from sqlalchemy.test.schema.Table import select [as 别名]
    def test_no_rowcount_on_selects_inserts(self):
        """assert that rowcount is only called on deletes and updates.

        This because cursor.rowcount can be expensive on some dialects
        such as Firebird.

        """

        engine = engines.testing_engine()
        metadata.bind = engine

        t = Table('t1', metadata,
            Column('data', String(10))
        )
        metadata.create_all()

        class BreakRowcountMixin(object):
            @property
            def rowcount(self):
                assert False

        execution_ctx_cls = engine.dialect.execution_ctx_cls
        engine.dialect.execution_ctx_cls = type("FakeCtx", 
                                            (BreakRowcountMixin, 
                                            execution_ctx_cls), 
                                            {})

        try:
            r = t.insert().execute({'data': 'd1'}, {'data': 'd2'},
                                   {'data': 'd3'})
            eq_(t.select().execute().fetchall(), [('d1', ), ('d2', ),
                ('d3', )])
            assert_raises(AssertionError, t.update().execute, {'data'
                          : 'd4'})
            assert_raises(AssertionError, t.delete().execute)
        finally:
            engine.dialect.execution_ctx_cls = execution_ctx_cls
开发者ID:chatch,项目名称:pinyin-toolkit,代码行数:39,代码来源:test_execute.py


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