• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python sql.Table类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: OOQuery

class OOQuery(object):
    def __init__(self, table, foreign_key=None):
        self.fields = None
        self.table = Table(table)
        self._select = self.table.select()
        self.parser = Parser(self.table, foreign_key)

    @property
    def select_on(self):
        if self.parser.joins:
            return self.parser.joins[-1]
        else:
            return self.table

    def select(self, fields=None):
        if fields:
            self.fields = [getattr(self.table, arg) for arg in fields]
            self._select = self.table.select(*self.fields)
        return self

    def where(self, domain):
        where = self.parser.parse(domain)
        self._select = self.select_on.select(*self.fields)
        self._select.where = where
        return self._select
开发者ID:gisce,项目名称:ooquery,代码行数:25,代码来源:ooquery.py


示例2: init

    def init(self):
        from trytond.modules import get_module_info
        with self.get_connection() as conn:
            cursor = conn.cursor()
            sql_file = os.path.join(os.path.dirname(__file__), 'init.sql')
            with open(sql_file) as fp:
                for line in fp.read().split(';'):
                    if (len(line) > 0) and (not line.isspace()):
                        cursor.execute(line)

            ir_module = Table('ir_module')
            ir_module_dependency = Table('ir_module_dependency')
            for module in ('ir', 'res'):
                state = 'uninstalled'
                if module in ('ir', 'res'):
                    state = 'to install'
                info = get_module_info(module)
                insert = ir_module.insert(
                    [ir_module.create_uid, ir_module.create_date,
                        ir_module.name, ir_module.state],
                    [[0, CurrentTimestamp(), module, state]])
                cursor.execute(*insert)
                cursor.execute('SELECT last_insert_rowid()')
                module_id, = cursor.fetchone()
                for dependency in info.get('depends', []):
                    insert = ir_module_dependency.insert(
                        [ir_module_dependency.create_uid,
                            ir_module_dependency.create_date,
                            ir_module_dependency.module,
                            ir_module_dependency.name,
                            ],
                        [[0, CurrentTimestamp(), module_id, dependency]])
                    cursor.execute(*insert)
            conn.commit()
开发者ID:coopengo,项目名称:trytond,代码行数:34,代码来源:database.py


示例3: test_0050_query_pagination

    def test_0050_query_pagination(self):
        """
        Test pagination via `nereid.contrib.QueryPagination.`
        """
        with Transaction().start(DB_NAME, USER, CONTEXT):
            self.setup_defaults()

            # Create a 100 addresses
            for id in xrange(0, 100):
                self.address_obj.create([{
                    'party': self.guest_party,
                    'name': 'User %s' % id,
                }])

            table = Table('party_address')
            select_query = table.select()

            pagination = QueryPagination(
                self.address_obj, select_query, table, page=1, per_page=10
            )

            self.assertEqual(pagination.count, 100)
            self.assertEqual(pagination.pages, 10)
            self.assertEqual(pagination.begin_count, 1)
            self.assertEqual(pagination.end_count, 10)
开发者ID:2cadz,项目名称:nereid,代码行数:25,代码来源:test_pagination.py


示例4: __register__

    def __register__(cls, module_name):
        cursor = Transaction().cursor
        model_data = Table('ir_model_data')

        # Migration from 3.0: new tax rates
        if module_name == 'account_nl':
            for old_id, new_id in (
                    ('tva_vente_19_6', 'tva_vente_taux_normal'),
                    ('tva_vente_7', 'tva_vente_taux_intermediaire'),
                    ('tva_vente_intracommunautaire_19_6',
                        'tva_vente_intracommunautaire_taux_normal'),
                    ('tva_vente_intracommunautaire_7',
                        'tva_vente_intracommunautaire_taux_intermediaire'),
                    ('tva_achat_19_6', 'tva_achat_taux_normal'),
                    ('tva_achat_7', 'tva_achat_taux_intermediaire'),
                    ('tva_achat_intracommunautaire_19_6',
                        'tva_achat_intracommunautaire_taux_normal'),
                    ):
                cursor.execute(*model_data.select(model_data.id,
                        where=(model_data.fs_id == new_id)
                        & (model_data.module == module_name)))
                if cursor.fetchone():
                    continue
                cursor.execute(*model_data.update(
                        columns=[model_data.fs_id],
                        values=[new_id],
                        where=(model_data.fs_id == old_id)
                        & (model_data.module == module_name)))

        super(TaxTemplate, cls).__register__(module_name)
开发者ID:FvD,项目名称:trytond_account_nl,代码行数:30,代码来源:account.py


示例5: restore_default_party_lang_from_4_2

    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,代码行数:33,代码来源:configuration.py


示例6: login_from_id

def login_from_id(user_id):
    with Transaction().new_transaction(readonly=True) as t:
        cursor = t.connection.cursor()
        table = Table('res_user')
        cursor.execute(*table.select(table.login,
                where=table.id == user_id))
        return cursor.fetchone()[0]
开发者ID:coopengo,项目名称:trytond,代码行数:7,代码来源:perf_analyzer.py


示例7: test_insert_subselect

 def test_insert_subselect(self):
     t1 = Table("t1")
     t2 = Table("t2")
     subquery = t2.select(t2.c1, t2.c2)
     query = t1.insert([t1.c1, t1.c2], subquery)
     self.assertEqual(str(query), 'INSERT INTO "t1" ("c1", "c2") ' 'SELECT "a"."c1", "a"."c2" FROM "t2" AS "a"')
     self.assertEqual(query.params, ())
开发者ID:ernestoluisrojas,项目名称:ShnergleServer,代码行数:7,代码来源:test_insert.py


示例8: __register__

    def __register__(cls, module_name):
        TableHandler = backend.get('TableHandler')
        cursor = Transaction().cursor

        super(ProductMedia, cls).__register__(module_name)

        media_table = cls.__table__()

        if TableHandler.table_exist(cursor, 'product_product_imageset'):
            # Migrate data from ProductImageSet table to ProductMedia table
            imageset_table = Table('product_product_imageset')

            cursor.execute(*media_table.insert(
                columns=[
                    media_table.sequence,
                    media_table.product, media_table.template,
                    media_table.static_file,
                ],
                values=imageset_table.select(
                    Literal(10),
                    imageset_table.product, imageset_table.template,
                    imageset_table.image
                )
            ))

            TableHandler.drop_table(
                cursor, 'product.product.imageset', 'product_product_imageset',
                cascade=True
            )
开发者ID:gautampanday,项目名称:nereid-catalog,代码行数:29,代码来源:product.py


示例9: test_order_query

 def test_order_query(self):
     table = Table('t')
     column = Column(table, 'c')
     query = table.select(column)
     self.assertEqual(str(Asc(query)),
         '(SELECT "a"."c" FROM "t" AS "a") ASC')
     self.assertEqual(str(Desc(query)),
         '(SELECT "a"."c" FROM "t" AS "a") DESC')
开发者ID:jefurry,项目名称:python-sql,代码行数:8,代码来源:test_order.py


示例10: test_update2

 def test_update2(self):
     t1 = Table('t1')
     t2 = Table('t2')
     query = t1.update([t1.c], ['foo'], from_=[t2], where=(t1.c == t2.c))
     self.assertEqual(str(query),
         'UPDATE "t1" AS "b" SET "c" = %s FROM "t2" AS "a" '
         'WHERE ("b"."c" = "a"."c")')
     self.assertEqual(query.params, ('foo',))
开发者ID:michaelfarrell76,项目名称:ExpertmentPlanner2,代码行数:8,代码来源:test_update.py


示例11: test_delete3

 def test_delete3(self):
     t1 = Table('t1')
     t2 = Table('t2')
     query = t1.delete(where=(t1.c.in_(t2.select(t2.c))))
     self.assertEqual(str(query),
         'DELETE FROM "t1" WHERE ("c" IN ('
         'SELECT "a"."c" FROM "t2" AS "a"))')
     self.assertEqual(query.params, ())
开发者ID:michaelfarrell76,项目名称:ExpertmentPlanner2,代码行数:8,代码来源:test_delete.py


示例12: test_lateral_select

    def test_lateral_select(self):
        t1 = Table('t1')
        t2 = Table('t2')
        lateral = Lateral(t2.select(where=t2.id == t1.t2))
        query = From([t1, lateral]).select()

        self.assertEqual(str(query),
            'SELECT * FROM "t1" AS "a", LATERAL '
            '(SELECT * FROM "t2" AS "c" WHERE ("c"."id" = "a"."t2")) AS "b"')
        self.assertEqual(query.params, ())
开发者ID:XasaKura,项目名称:Xsql,代码行数:10,代码来源:test_lateral.py


示例13: test_with

    def test_with(self):
        t1 = Table('t1')
        w = With(query=t1.select(t1.c1))

        query = self.table.delete(with_=[w],
            where=self.table.c2.in_(w.select(w.c3)))
        self.assertEqual(str(query),
            'WITH a AS (SELECT "b"."c1" FROM "t1" AS "b") '
            'DELETE FROM "t" WHERE ("c2" IN (SELECT "a"."c3" FROM a AS "a"))')
        self.assertEqual(query.params, ())
开发者ID:michaelfarrell76,项目名称:ExpertmentPlanner2,代码行数:10,代码来源:test_delete.py


示例14: __register__

 def __register__(cls, module_name):
     cursor = Transaction().cursor
     model_data = Table('ir_model_data')
     # Migration from 1.6: corrected misspelling of ounce (was once)
     cursor.execute(*model_data.update(
             columns=[model_data.fs_id],
             values=['uom_ounce'],
             where=(model_data.fs_id == 'uom_once')
             & (model_data.module == 'product')))
     super(Uom, cls).__register__(module_name)
开发者ID:aleibrecht,项目名称:tryton-modules-ar,代码行数:10,代码来源:uom.py


示例15: migrate

    def migrate(self):
        obj = objectify.fromstring(self.content)
        t = Table('ir_model_data')
        for xml_record in obj.iter(tag='record'):
            record = self._record(xml_record)
            self.records.append(record)
            sp = []
            for field in self.search_params.get(record.model, record.vals.keys()):
                sp.append((field, '=', record.vals[field]))
            logger.info('Trying to find existing record with query: {}'.format(
                sp
            ))
            table = record.model.replace('.', '_')
            q = OOQuery(table)
            sql = q.select(['id']).where(sp)
            logger.debug(tuple(sql))
            self.cursor.execute(*sql)
            res_id = self.cursor.fetchone()
            if res_id:
                res_id = res_id[0]
                logger.info('Record {}.{} found! ({} id:{})'.format(
                    self.module, record.id, record.model, res_id
                ))
            else:
                logger.info('Record {}.{} not found!'.format(
                    self.module, record.id
                ))
                # We have to create the model
                table_model = Table(record.model.replace('.', '_'))
                columns = []
                values = []
                for col, value in record.vals.items():
                    columns.append(getattr(table_model, col))
                    values.append(value)

                sql = table_model.insert(
                    columns=columns, values=[values], returning=[table_model.id]
                )
                logger.debug(tuple(sql))
                self.cursor.execute(*sql)
                res_id = self.cursor.fetchone()[0]
                logger.info('Creating record {}.{} ({} id:{})'.format(
                    self.module, record.id, record.model, res_id
                ))

            sql = t.insert(
                columns=[t.name, t.model, t.noupdate, t.res_id, t.module],
                values=[(record.id, record.model, record.noupdate, res_id,
                         self.module)]
            )
            logger.debug(tuple(sql))
            logger.info('Linking model data {}.{} -> record {} id:{}'.format(
                self.module, record.id, record.model, res_id
            ))
            self.cursor.execute(*sql)
开发者ID:gisce,项目名称:oopgrade,代码行数:55,代码来源:data.py


示例16: test_join_subselect

 def test_join_subselect(self):
     t1 = Table('t1')
     t2 = Table('t2')
     select = t2.select()
     join = Join(t1, select)
     join.condition = t1.c == select.c
     with AliasManager():
         self.assertEqual(str(join),
             '"t1" AS "a" INNER JOIN (SELECT * FROM "t2" AS "c") AS "b" '
             'ON ("a"."c" = "b"."c")')
         self.assertEqual(join.params, ())
开发者ID:Shoreray,项目名称:bss_final,代码行数:11,代码来源:test_join.py


示例17: test_with

    def test_with(self):
        t1 = Table('t1')
        w = With(query=t1.select())

        query = self.table.insert(
            [self.table.c1],
            with_=[w],
            values=w.select())
        self.assertEqual(str(query),
            'WITH "a" AS (SELECT * FROM "t1" AS "b") '
            'INSERT INTO "t" ("c1") SELECT * FROM "a" AS "a"')
        self.assertEqual(query.params, ())
开发者ID:XasaKura,项目名称:Xsql,代码行数:12,代码来源:test_insert.py


示例18: __register__

    def __register__(cls, module_name):
        cursor = Transaction().cursor
        model_data = Table('ir_model_data')
        # Migration from 1.2: packing renamed into shipment
        cursor.execute(*model_data.update(
                columns=[model_data.fs_id],
                values=[Overlay(model_data.fs_id, 'shipment',
                        Position('packing', model_data.fs_id),
                        len('packing'))],
                where=model_data.fs_id.like('%packing%')
                & (model_data.module == module_name)))

        super(Purchase, cls).__register__(module_name)
开发者ID:kret0s,项目名称:tryton3_8,代码行数:13,代码来源:purchase.py


示例19: test_with

    def test_with(self):
        t1 = Table('t1')
        w = With(query=t1.select(t1.c1))

        query = self.table.update(
            [self.table.c2],
            with_=[w],
            values=[w.select(w.c3, where=w.c4 == 2)])
        self.assertEqual(str(query),
            'WITH b AS (SELECT "c"."c1" FROM "t1" AS "c") '
            'UPDATE "t" SET "c2" = (SELECT "b"."c3" FROM b AS "b" '
            'WHERE ("b"."c4" = %s))')
        self.assertEqual(query.params, (2,))
开发者ID:michaelfarrell76,项目名称:ExpertmentPlanner2,代码行数:13,代码来源:test_update.py


示例20: clean

 def clean(cls, dbname):
     with Transaction().new_transaction() as transaction,\
             transaction.connection.cursor() as cursor:
         table = Table('ir_cache')
         cursor.execute(*table.select(table.timestamp, table.name))
         timestamps = {}
         for timestamp, name in cursor.fetchall():
             timestamps[name] = timestamp
     for inst in cls._cache_instance:
         if inst._name in timestamps:
             with inst._lock:
                 if (not inst._timestamp
                         or timestamps[inst._name] > inst._timestamp):
                     inst._timestamp = timestamps[inst._name]
                     inst._empty(dbname)
开发者ID:coopengo,项目名称:trytond,代码行数:15,代码来源:cache.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python sql_manager.change_pass函数代码示例发布时间:2022-05-27
下一篇:
Python sql.Flavor类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap