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


Python Table.join方法代码示例

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


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

示例1: restore_default_party_lang_from_4_2

# 需要导入模块: from sql import Table [as 别名]
# 或者: from sql.Table import join [as 别名]
    def restore_default_party_lang_from_4_2(cls):
        from trytond.transaction import Transaction
        from sql import Null, Table, Cast
        from sql.operators import Concat
        from trytond.pool import Pool

        TableHandler = backend.get('TableHandler')
        if not TableHandler.table_exist('ir_property'):
            return

        pool = Pool()
        property = Table('ir_property')
        Lang = pool.get('ir.lang')
        field = pool.get('ir.model.field').__table__()
        lang = Lang.__table__()
        cursor = Transaction().connection.cursor()

        query_table = property.join(lang, condition=(
                property.value == Concat('ir.lang,', Cast(lang.id, 'VARCHAR'))
                )).join(field, condition=((property.field == field.id) &
                        (field.name == 'lang')))

        cursor.execute(
            *query_table.select(lang.id, where=property.res == Null))
        result = cursor.fetchone()
        if result:
            result = list(result)
            default_lang = Lang(result[0])
            print('Default Language restored [%s]' % default_lang.rec_name)
            pool.get('party.configuration.party_lang'
                ).create([{'party_lang': default_lang}])
        else:
            print('No default language on party configuration found')
开发者ID:coopengo,项目名称:party,代码行数:35,代码来源:configuration.py

示例2: clean_properties_from_4_2

# 需要导入模块: from sql import Table [as 别名]
# 或者: from sql.Table import join [as 别名]
    def clean_properties_from_4_2(cls):
        from sql import Null, Table, Cast
        from sql.operators import Like, Concat

        TableHandler = backend.get('TableHandler')
        if not TableHandler.table_exist('ir_property'):
            return

        property = Table('ir_property')

        cursor = Transaction().connection.cursor()
        cursor.execute(*property.select(property.res,
                where=property.res != Null))

        res_model_names = list(set([x[0].split(',')[0]
                for x in cursor.fetchall()]))

        to_delete = {}

        for res_model_name in res_model_names:
            table_name = res_model_name.replace('.', '_')
            res_model = Table(table_name)
            query_table = property.join(res_model, 'LEFT OUTER', condition=(
                    property.res == Concat(res_model_name + ',',
                        Cast(res_model.id, 'VARCHAR'))
                    ))
            cursor.execute(*query_table.select(property.id,
                    where=Like(property.res, res_model_name + ',%') &
                    (res_model.id == Null)))
            property_ids = [x[0] for x in cursor.fetchall()]
            if property_ids:
                to_delete[res_model_name] = property_ids
        if to_delete:
            cursor.execute(
                *property.delete(where=property.id.in_(
                        sum([p for p in list(to_delete.values())], []))))
            for res_model_name, property_ids in list(to_delete.items()):
                if property_ids:
                    print('[%s] - %s Inconsistent record(s) removed' % (
                        res_model_name, len(property_ids)))
        else:
            print('Nothing to do - Exisiting property records are clean')
开发者ID:coopengo,项目名称:party,代码行数:44,代码来源:party.py

示例3: OOQuery

# 需要导入模块: from sql import Table [as 别名]
# 或者: from sql.Table import join [as 别名]
                return {
                    'table_2': {
                        'constraint_name': 'fk_contraint_name',
                        'table_name': 'table',
                        'column_name': 'table_2',
                        'foreign_table_name': 'table2',
                        'foreign_column_name': 'id'
                    }
                }

            q = OOQuery('table', dummy_fk)
            sql = q.select(['field1', 'field2']).where([
                ('table_2.code', '=', 'XXX')
            ])
            t = Table('table')
            join = t.join(Table('table2'))
            join.condition = join.left.table_2 == join.right.id
            sel = join.select(t.field1, t.field2)
            sel.where = And((join.right.code == 'XXX',))
            expect(tuple(sql)).to(equal(tuple(sel)))

        with it('must support deep joins'):
            def dummy_fk(table):
                if table == 'table':
                    return {
                        'table_2_id': {
                            'constraint_name': 'fk_contraint_name',
                            'table_name': 'table',
                            'column_name': 'table_2_id',
                            'foreign_table_name': 'table2',
                            'foreign_column_name': 'id'
开发者ID:gisce,项目名称:ooquery,代码行数:33,代码来源:ooquery_spec.py


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