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


Python connection.commit方法代码示例

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


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

示例1: run

# 需要导入模块: from django.db import connection [as 别名]
# 或者: from django.db.connection import commit [as 别名]
def run(self):
        print('Starting DatabasePusher')
        to_commit = io.StringIO('')
        total_commits = 0
        while self.producer_finished.value == 0 or self.mock_data_queue.qsize() > 0:
            count = 0
            num_to_commit = 0
            while not self.mock_data_queue.empty() and count < 5:
                count += 1
                image_csv, num_images, header = self.mock_data_queue.get()
                to_commit = io.StringIO(to_commit.getvalue() + image_csv.getvalue())
                num_to_commit += num_images
                total_commits += num_images
                if num_to_commit >= 100000 or self.producer_finished.value == 1:
                    print('Pushing', num_to_commit, 'records to database')
                    start_time = time.time()
                    with connection.cursor() as cur:
                        cur.copy_from(to_commit, 'image', columns=header)
                    connection.commit()
                    commit_time = time.time() - start_time
                    print('Committed', num_to_commit, 'in', commit_time,
                          'seconds', '(' + str(num_to_commit / commit_time), 'per second)')
                    print('Progress: ', total_commits / self.num_images_to_push * 100, '%', sep='')
                    to_commit = io.StringIO('')
        print('Done pushing after committing', total_commits) 
开发者ID:cc-archive,项目名称:open-ledger,代码行数:27,代码来源:mocker.py

示例2: fix_all_users

# 需要导入模块: from django.db import connection [as 别名]
# 或者: from django.db.connection import commit [as 别名]
def fix_all_users(self, realm: Realm) -> None:
        user_profiles = list(UserProfile.objects.filter(
            realm=realm,
            is_bot=False,
        ))
        for user_profile in user_profiles:
            fix(user_profile)
            connection.commit() 
开发者ID:zulip,项目名称:zulip,代码行数:10,代码来源:fix_unreads.py

示例3: fix_emails

# 需要导入模块: from django.db import connection [as 别名]
# 或者: from django.db.connection import commit [as 别名]
def fix_emails(self, realm: Optional[Realm], emails: List[str]) -> None:

        for email in emails:
            try:
                user_profile = self.get_user(email, realm)
            except CommandError:
                print(f"e-mail {email} doesn't exist in the realm {realm}, skipping")
                return

            fix(user_profile)
            connection.commit() 
开发者ID:zulip,项目名称:zulip,代码行数:13,代码来源:fix_unreads.py

示例4: executeSQL_now

# 需要导入模块: from django.db import connection [as 别名]
# 或者: from django.db.connection import commit [as 别名]
def executeSQL_now(conn_string, sqls, db=None, **kwargs):
    resultset = []
    for sql in sqls:
        try:
            db = connect(conn_string)
            gCurs = db.cursor()

            try:
                gCurs.execute(sql)
            except Exception, E:
                print str(E)
                raise

            try:
                result = gCurs.fetchall()
            except:
                result = ()
            gCurs.close()
            db.commit()

            results = []
            for n in result: results.append(n)
            resultset.append(results)

        except Exception, E:
            try:
                gCurs.close()
            except:
                pass
            resultset.append(E) 
开发者ID:CalthorpeAnalytics,项目名称:urbanfootprint,代码行数:32,代码来源:uf_toolbox.py

示例5: signal_probe_change

# 需要导入模块: from django.db import connection [as 别名]
# 或者: from django.db.connection import commit [as 别名]
def signal_probe_change():
    try:
        cur = connection.cursor()
        cur.execute('NOTIFY {}'.format(postgresql_channel))
        connection.commit()
    except Exception as db_err:
        logger.error("Could not signal probe change: %s", db_err)
        connection.close_if_unusable_or_obsolete() 
开发者ID:zentralopensource,项目名称:zentral,代码行数:10,代码来源:sync.py

示例6: increase_row_integer

# 需要导入模块: from django.db import connection [as 别名]
# 或者: from django.db.connection import commit [as 别名]
def increase_row_integer(
    table_name: str,
    set_field: str,
    where_field: str,
    where_value,
):
    """Increase the integer in the row specified by the where fields.

    Given a primary key, a field set_field, and a pair (where_field,
    where_value), it increases the field in the appropriate row

    :param table_name: Primary key to detect workflow
    :param set_field: name of the field to be increased
    :param where_field: Field used to filter the row in the table
    :param where_value: Value of the previous field to filter the row
    :return: The table in the workflow pointed by PK is modified.
    """
    query = sql.SQL('UPDATE {0} SET {1} = {1} + 1 WHERE {2} = %s').format(
        sql.Identifier(table_name),
        OnTaskDBIdentifier(set_field),
        OnTaskDBIdentifier(where_field),
        sql.Literal(where_value))

    # Execute the query
    with connection.connection.cursor() as cursor:
        cursor.execute(query, [where_value])
        connection.commit() 
开发者ID:abelardopardo,项目名称:ontask_b,代码行数:29,代码来源:row_queries.py

示例7: _delete_all_tables

# 需要导入模块: from django.db import connection [as 别名]
# 或者: from django.db.connection import commit [as 别名]
def _delete_all_tables():
        """Delete all tables related to existing workflows."""
        cursor = connection.cursor()
        table_list = connection.introspection.get_table_list(cursor)
        for tinfo in table_list:
            if not tinfo.name.startswith(models.Workflow.table_prefix):
                continue
            cursor.execute('DROP TABLE "{0}";'.format(tinfo.name))

        # To make sure the table is dropped.
        connection.commit()
        return 
开发者ID:abelardopardo,项目名称:ontask_b,代码行数:14,代码来源:__init__.py

示例8: _do_vacuum

# 需要导入模块: from django.db import connection [as 别名]
# 或者: from django.db.connection import commit [as 别名]
def _do_vacuum(self, full=False):
        cursor = connection.cursor()
        if full:
            print("Vacuuming (full) table {}...".format(self._model._meta.db_table))
            cursor.execute("VACUUM FULL {}".format(self._model._meta.db_table))
        else:
            print("Vacuuming table {}...".format(self._model._meta.db_table))
            cursor.execute("VACUUM {}".format(self._model._meta.db_table))
        connection.commit() 
开发者ID:kobotoolbox,项目名称:kpi,代码行数:11,代码来源:delete_base_command.py

示例9: run

# 需要导入模块: from django.db import connection [as 别名]
# 或者: from django.db.connection import commit [as 别名]
def run(self):
        while True:
            # LISTEN query
            try:
                cur = connection.cursor()
                cur.execute('LISTEN {}'.format(postgresql_channel))
                connection.commit()
            except Exception as db_err:
                connection.close_if_unusable_or_obsolete()
                self.error_state = True
                sleep_time = 2 * (1 + random.random())
                logger.error("Could not execute the LISTEN query: %s. Sleep %ss.", db_err, sleep_time)
                time.sleep(sleep_time)
                continue

            # are we recovering from an error ?
            if self.error_state:
                # need to clear the probe_view. We might have missed some updates
                probe_view = self.probe_view()
                if probe_view:
                    logger.info("DB error recovery. Clear probe view.")
                    probe_view.clear()
                else:
                    break
                self.error_state = False

            logger.info("Waiting for notifications on channel '%s'", postgresql_channel)
            pg_con = connection.connection
            while True:
                if select.select([pg_con], [], [], 5) == ([], [], []):
                    pass
                else:
                    try:
                        pg_con.poll()
                    except Exception as db_err:
                        logger.error("Could not poll() the DB connection: %s", db_err)
                        connection.close_if_unusable_or_obsolete()
                        break
                    if pg_con.notifies:
                        # clear notifications
                        while pg_con.notifies:
                            pg_con.notifies.pop()
                        logger.info("Received notification on channel '%s'", postgresql_channel)
                        probe_view = self.probe_view()
                        if probe_view:
                            probe_view.clear()
                        else:
                            return 
开发者ID:zentralopensource,项目名称:zentral,代码行数:50,代码来源:sync.py


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