db.py 文件源码

python
阅读 36 收藏 0 点赞 0 评论 0

项目:nav 作者: UNINETT 项目源码 文件源码
def execute(self, statement, values=None, commit=1):
        """
        Runs a synchronized database query, ignoring any result rows.
        Automatically re-opens a troubled connection, and handles errors.

        """
        cursor = None
        try:
            cursor = self.cursor()
            cursor.execute(statement, values)
            LOGGER.debug("Executed: %s", cursor.query)
            if commit:
                try:
                    self.db.commit()
                except Exception:
                    LOGGER.critical("Failed to commit")
        except psycopg2.IntegrityError:
            LOGGER.critical("Database integrity error, throwing away update",
                            exc_info=True)
            LOGGER.debug("Tried to execute: %s", cursor.query)
            if commit:
                self.db.rollback()
        except Exception:
            LOGGER.critical("Could not execute statement: %s",
                            cursor.query if cursor else statement,
                            exc_info=True)
            if commit:
                self.db.rollback()
            raise DbError()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号